fix: support subsonic endpoints without view suffix

This commit is contained in:
2026-04-03 20:56:04 +03:00
parent 2956a302e0
commit 3c284bc414

View File

@@ -84,32 +84,32 @@ func NewRouter(cfg config.Config, database *sql.DB, scanService *scanner.Service
}) })
r.Route("/rest", func(rest chi.Router) { 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()) 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()) writeJSON(w, http.StatusOK, subsonic.PingResponse())
}) })
rest.Group(func(authed chi.Router) { rest.Group(func(authed chi.Router) {
authed.Use(application.requireSubsonicAuth) authed.Use(application.requireSubsonicAuth)
authed.Get("/getArtists.view", application.subsonicArtists) restGet(authed, "getArtists", application.subsonicArtists)
authed.Get("/getArtist.view", application.subsonicArtistByID) restGet(authed, "getArtist", application.subsonicArtistByID)
authed.Get("/getAlbum.view", application.subsonicAlbumByID) restGet(authed, "getAlbum", application.subsonicAlbumByID)
authed.Get("/getSong.view", application.subsonicSongByID) restGet(authed, "getSong", application.subsonicSongByID)
authed.Get("/getRandomSongs.view", application.subsonicRandomSongs) restGet(authed, "getRandomSongs", application.subsonicRandomSongs)
authed.Get("/search3.view", application.subsonicSearch3) restGet(authed, "search3", application.subsonicSearch3)
authed.Get("/getStarred2.view", application.subsonicStarred2) restGet(authed, "getStarred2", application.subsonicStarred2)
authed.Get("/star.view", application.subsonicStar) restGet(authed, "star", application.subsonicStar)
authed.Get("/unstar.view", application.subsonicUnstar) restGet(authed, "unstar", application.subsonicUnstar)
authed.Get("/getPlaylists.view", application.subsonicPlaylists) restGet(authed, "getPlaylists", application.subsonicPlaylists)
authed.Get("/getPlaylist.view", application.subsonicPlaylistByID) restGet(authed, "getPlaylist", application.subsonicPlaylistByID)
authed.Get("/createPlaylist.view", application.subsonicCreatePlaylist) restGet(authed, "createPlaylist", application.subsonicCreatePlaylist)
authed.Get("/updatePlaylist.view", application.subsonicUpdatePlaylist) restGet(authed, "updatePlaylist", application.subsonicUpdatePlaylist)
authed.Get("/getScanStatus.view", application.subsonicScanStatus) restGet(authed, "getScanStatus", application.subsonicScanStatus)
authed.Get("/startScan.view", application.subsonicStartScan) restGet(authed, "startScan", application.subsonicStartScan)
authed.Get("/getCoverArt.view", application.subsonicCoverArt) restGet(authed, "getCoverArt", application.subsonicCoverArt)
authed.Get("/stream.view", application.subsonicStream) restGet(authed, "stream", application.subsonicStream)
authed.Get("/scrobble.view", application.subsonicScrobble) restGet(authed, "scrobble", application.subsonicScrobble)
}) })
}) })
@@ -884,3 +884,8 @@ func detectFrontendRoot() string {
return "" return ""
} }
func restGet(router chi.Router, endpoint string, handler http.HandlerFunc) {
router.Get("/"+endpoint, handler)
router.Get("/"+endpoint+".view", handler)
}