feat: add subsonic library discovery endpoints
This commit is contained in:
@@ -97,6 +97,12 @@ func NewRouter(cfg config.Config, database *sql.DB, scanService *scanner.Service
|
||||
restGet(authed, "getAlbum", application.subsonicAlbumByID)
|
||||
restGet(authed, "getSong", application.subsonicSongByID)
|
||||
restGet(authed, "getRandomSongs", application.subsonicRandomSongs)
|
||||
restGet(authed, "getAlbumList2", application.subsonicAlbumList2)
|
||||
restGet(authed, "getMusicFolders", application.subsonicMusicFolders)
|
||||
restGet(authed, "getGenres", application.subsonicGenres)
|
||||
restGet(authed, "getPodcasts", application.subsonicPodcasts)
|
||||
restGet(authed, "getNewestPodcasts", application.subsonicNewestPodcasts)
|
||||
restGet(authed, "getInternetRadioStations", application.subsonicInternetRadioStations)
|
||||
restGet(authed, "search3", application.subsonicSearch3)
|
||||
restGet(authed, "getStarred2", application.subsonicStarred2)
|
||||
restGet(authed, "star", application.subsonicStar)
|
||||
@@ -456,6 +462,46 @@ func (a app) subsonicRandomSongs(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, subsonic.RandomSongsResponse(tracks))
|
||||
}
|
||||
|
||||
func (a app) subsonicAlbumList2(w http.ResponseWriter, r *http.Request) {
|
||||
size := 60
|
||||
if raw := strings.TrimSpace(r.URL.Query().Get("size")); raw != "" {
|
||||
if parsed := parsePositiveInt(raw); parsed > 0 {
|
||||
size = parsed
|
||||
}
|
||||
}
|
||||
albums, err := a.library.Albums(r.Context(), size)
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, subsonic.ErrorResponse(0, "failed to load albums"))
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, subsonic.AlbumList2Response(albums))
|
||||
}
|
||||
|
||||
func (a app) subsonicMusicFolders(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, subsonic.MusicFoldersResponse())
|
||||
}
|
||||
|
||||
func (a app) subsonicGenres(w http.ResponseWriter, r *http.Request) {
|
||||
genres, err := a.library.Genres(r.Context())
|
||||
if err != nil {
|
||||
writeJSON(w, http.StatusInternalServerError, subsonic.ErrorResponse(0, "failed to load genres"))
|
||||
return
|
||||
}
|
||||
writeJSON(w, http.StatusOK, subsonic.GenresResponse(genres))
|
||||
}
|
||||
|
||||
func (a app) subsonicPodcasts(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, subsonic.PodcastsResponse())
|
||||
}
|
||||
|
||||
func (a app) subsonicNewestPodcasts(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, subsonic.NewestPodcastsResponse())
|
||||
}
|
||||
|
||||
func (a app) subsonicInternetRadioStations(w http.ResponseWriter, r *http.Request) {
|
||||
writeJSON(w, http.StatusOK, subsonic.InternetRadioStationsResponse())
|
||||
}
|
||||
|
||||
func (a app) subsonicSearch3(w http.ResponseWriter, r *http.Request) {
|
||||
query := strings.TrimSpace(r.URL.Query().Get("query"))
|
||||
if query == "" {
|
||||
|
||||
Reference in New Issue
Block a user