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) {
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)
}