Subsonic: internet radio, chat, bookmarks, play queue, scanner status endpoints
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
package subsonic
|
||||
|
||||
import "git.noroutes.net/NoRoutes/vibetunes/internal/database"
|
||||
|
||||
func init() {
|
||||
register("getInternetRadioStations", handleGetInternetRadioStations)
|
||||
register("createInternetRadioStation", handleCreateInternetRadioStation)
|
||||
register("updateInternetRadioStation", handleUpdateInternetRadioStation)
|
||||
register("deleteInternetRadioStation", handleDeleteInternetRadioStation)
|
||||
}
|
||||
|
||||
func handleGetInternetRadioStations(rc *Context) *apiError {
|
||||
stations, err := database.ListRadioStations(rc.Server.DB)
|
||||
if err != nil {
|
||||
return newError(ErrGeneric, err.Error())
|
||||
}
|
||||
out := &InternetRadioStations{}
|
||||
for _, s := range stations {
|
||||
out.InternetRadioStation = append(out.InternetRadioStation, InternetRadioStation{
|
||||
ID: s.ID, Name: s.Name, StreamURL: s.StreamURL, HomepageURL: s.HomepageURL,
|
||||
})
|
||||
}
|
||||
rc.Response = newResponse()
|
||||
rc.Response.InternetRadioStations = out
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleCreateInternetRadioStation(rc *Context) *apiError {
|
||||
if !rc.User.IsAdmin {
|
||||
return errUnauthorized("managing internet radio stations")
|
||||
}
|
||||
streamURL, aerr := rc.Params.Required("streamUrl")
|
||||
if aerr != nil {
|
||||
return aerr
|
||||
}
|
||||
name, aerr := rc.Params.Required("name")
|
||||
if aerr != nil {
|
||||
return aerr
|
||||
}
|
||||
homepage := rc.Params.Get("homepageUrl")
|
||||
if _, err := database.CreateRadioStation(rc.Server.DB, name, streamURL, homepage); err != nil {
|
||||
return newError(ErrGeneric, err.Error())
|
||||
}
|
||||
rc.Response = newResponse()
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleUpdateInternetRadioStation(rc *Context) *apiError {
|
||||
if !rc.User.IsAdmin {
|
||||
return errUnauthorized("managing internet radio stations")
|
||||
}
|
||||
id, aerr := rc.Params.Required("id")
|
||||
if aerr != nil {
|
||||
return aerr
|
||||
}
|
||||
streamURL, aerr := rc.Params.Required("streamUrl")
|
||||
if aerr != nil {
|
||||
return aerr
|
||||
}
|
||||
name, aerr := rc.Params.Required("name")
|
||||
if aerr != nil {
|
||||
return aerr
|
||||
}
|
||||
homepage := rc.Params.Get("homepageUrl")
|
||||
if _, err := database.GetRadioStation(rc.Server.DB, id); err != nil {
|
||||
return errNotFound("Internet radio station")
|
||||
}
|
||||
if err := database.UpdateRadioStation(rc.Server.DB, id, name, streamURL, homepage); err != nil {
|
||||
return newError(ErrGeneric, err.Error())
|
||||
}
|
||||
rc.Response = newResponse()
|
||||
return nil
|
||||
}
|
||||
|
||||
func handleDeleteInternetRadioStation(rc *Context) *apiError {
|
||||
if !rc.User.IsAdmin {
|
||||
return errUnauthorized("managing internet radio stations")
|
||||
}
|
||||
id, aerr := rc.Params.Required("id")
|
||||
if aerr != nil {
|
||||
return aerr
|
||||
}
|
||||
if _, err := database.GetRadioStation(rc.Server.DB, id); err != nil {
|
||||
return errNotFound("Internet radio station")
|
||||
}
|
||||
if err := database.DeleteRadioStation(rc.Server.DB, id); err != nil {
|
||||
return newError(ErrGeneric, err.Error())
|
||||
}
|
||||
rc.Response = newResponse()
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user