From 3c284bc414bd399ee6f803cc47ff110aedc27190 Mon Sep 17 00:00:00 2001 From: benya Date: Fri, 3 Apr 2026 20:56:04 +0300 Subject: [PATCH] fix: support subsonic endpoints without view suffix --- internal/httpapi/router.go | 45 +++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/internal/httpapi/router.go b/internal/httpapi/router.go index 57a914e..f2c14ae 100644 --- a/internal/httpapi/router.go +++ b/internal/httpapi/router.go @@ -84,32 +84,32 @@ func NewRouter(cfg config.Config, database *sql.DB, scanService *scanner.Service }) r.Route("/rest", func(rest chi.Router) { - rest.Get("/ping.view", func(w http.ResponseWriter, r *http.Request) { + restGet(rest, "ping", func(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, subsonic.PingResponse()) }) - rest.Get("/getLicense.view", func(w http.ResponseWriter, r *http.Request) { + restGet(rest, "getLicense", func(w http.ResponseWriter, r *http.Request) { writeJSON(w, http.StatusOK, subsonic.PingResponse()) }) rest.Group(func(authed chi.Router) { authed.Use(application.requireSubsonicAuth) - authed.Get("/getArtists.view", application.subsonicArtists) - authed.Get("/getArtist.view", application.subsonicArtistByID) - authed.Get("/getAlbum.view", application.subsonicAlbumByID) - authed.Get("/getSong.view", application.subsonicSongByID) - authed.Get("/getRandomSongs.view", application.subsonicRandomSongs) - authed.Get("/search3.view", application.subsonicSearch3) - authed.Get("/getStarred2.view", application.subsonicStarred2) - authed.Get("/star.view", application.subsonicStar) - authed.Get("/unstar.view", application.subsonicUnstar) - authed.Get("/getPlaylists.view", application.subsonicPlaylists) - authed.Get("/getPlaylist.view", application.subsonicPlaylistByID) - authed.Get("/createPlaylist.view", application.subsonicCreatePlaylist) - authed.Get("/updatePlaylist.view", application.subsonicUpdatePlaylist) - authed.Get("/getScanStatus.view", application.subsonicScanStatus) - authed.Get("/startScan.view", application.subsonicStartScan) - authed.Get("/getCoverArt.view", application.subsonicCoverArt) - authed.Get("/stream.view", application.subsonicStream) - authed.Get("/scrobble.view", application.subsonicScrobble) + restGet(authed, "getArtists", application.subsonicArtists) + restGet(authed, "getArtist", application.subsonicArtistByID) + restGet(authed, "getAlbum", application.subsonicAlbumByID) + restGet(authed, "getSong", application.subsonicSongByID) + restGet(authed, "getRandomSongs", application.subsonicRandomSongs) + restGet(authed, "search3", application.subsonicSearch3) + restGet(authed, "getStarred2", application.subsonicStarred2) + restGet(authed, "star", application.subsonicStar) + restGet(authed, "unstar", application.subsonicUnstar) + restGet(authed, "getPlaylists", application.subsonicPlaylists) + restGet(authed, "getPlaylist", application.subsonicPlaylistByID) + restGet(authed, "createPlaylist", application.subsonicCreatePlaylist) + restGet(authed, "updatePlaylist", application.subsonicUpdatePlaylist) + restGet(authed, "getScanStatus", application.subsonicScanStatus) + restGet(authed, "startScan", application.subsonicStartScan) + restGet(authed, "getCoverArt", application.subsonicCoverArt) + restGet(authed, "stream", application.subsonicStream) + restGet(authed, "scrobble", application.subsonicScrobble) }) }) @@ -884,3 +884,8 @@ func detectFrontendRoot() string { return "" } + +func restGet(router chi.Router, endpoint string, handler http.HandlerFunc) { + router.Get("/"+endpoint, handler) + router.Get("/"+endpoint+".view", handler) +}