mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-26 03:49:56 +01:00
Supporting json output (except for errors)
This commit is contained in:
parent
7c82af75f5
commit
9d41f5a39f
11 changed files with 114 additions and 99 deletions
|
|
@ -8,6 +8,7 @@ import (
|
|||
type ControllerInterface interface {
|
||||
GetString(key string, def ...string) string
|
||||
CustomAbort(status int, body string)
|
||||
SendError(errorCode int, message ...interface{})
|
||||
}
|
||||
|
||||
func Validate(controller ControllerInterface) {
|
||||
|
|
@ -23,7 +24,7 @@ func checkParameters(c ControllerInterface) {
|
|||
|
||||
for _, p := range requiredParameters {
|
||||
if c.GetString(p) == "" {
|
||||
cancel(c, responses.ERROR_MISSING_PARAMETER)
|
||||
abortRequest(c, responses.ERROR_MISSING_PARAMETER)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -32,10 +33,10 @@ func authenticate(c ControllerInterface) {
|
|||
user := c.GetString("u")
|
||||
pass := c.GetString("p") // TODO Handle hex-encoded password
|
||||
if user != beego.AppConfig.String("user") || pass != beego.AppConfig.String("password") {
|
||||
cancel(c, responses.ERROR_AUTHENTICATION_FAIL)
|
||||
abortRequest(c, responses.ERROR_AUTHENTICATION_FAIL)
|
||||
}
|
||||
}
|
||||
|
||||
func cancel(c ControllerInterface, code int) {
|
||||
c.CustomAbort(200, string(responses.NewError(code)))
|
||||
func abortRequest(c ControllerInterface, code int) {
|
||||
c.SendError(code)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue