From 314e9632d72dd7cd68044f9d69295123fff78f80 Mon Sep 17 00:00:00 2001 From: sentriz Date: Fri, 2 Feb 2024 19:57:03 +0000 Subject: [PATCH] fix(playlist): return new playlist id for createPlaylist fixes #464 --- server/ctrlsubsonic/ctrl.go | 2 +- server/ctrlsubsonic/handlers_playlist.go | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/server/ctrlsubsonic/ctrl.go b/server/ctrlsubsonic/ctrl.go index 189842f2..12d0bab2 100644 --- a/server/ctrlsubsonic/ctrl.go +++ b/server/ctrlsubsonic/ctrl.go @@ -111,7 +111,7 @@ func New(dbc *db.DB, scannr *scanner.Scanner, musicPaths []MusicPath, podcastsPa c.Handle("/getUser", chain(resp(c.ServeGetUser))) c.Handle("/getPlaylists", chain(resp(c.ServeGetPlaylists))) c.Handle("/getPlaylist", chain(resp(c.ServeGetPlaylist))) - c.Handle("/createPlaylist", chain(resp(c.ServeCreatePlaylist))) + c.Handle("/createPlaylist", chain(resp(c.ServeCreateOrUpdatePlaylist))) c.Handle("/updatePlaylist", chain(resp(c.ServeUpdatePlaylist))) c.Handle("/deletePlaylist", chain(resp(c.ServeDeletePlaylist))) c.Handle("/savePlayQueue", chain(resp(c.ServeSavePlayQueue))) diff --git a/server/ctrlsubsonic/handlers_playlist.go b/server/ctrlsubsonic/handlers_playlist.go index ae43cb2f..ca0c6e5c 100644 --- a/server/ctrlsubsonic/handlers_playlist.go +++ b/server/ctrlsubsonic/handlers_playlist.go @@ -67,7 +67,7 @@ func (c *Controller) ServeGetPlaylist(r *http.Request) *spec.Response { return sub } -func (c *Controller) ServeCreatePlaylist(r *http.Request) *spec.Response { +func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response { user := r.Context().Value(CtxUser).(*db.User) params := r.Context().Value(CtxParams).(params.Params) @@ -79,9 +79,8 @@ func (c *Controller) ServeCreatePlaylist(r *http.Request) *spec.Response { playlist = *pl } - // update meta info if playlist.UserID != 0 && playlist.UserID != user.ID { - return spec.NewResponse() + return spec.NewError(50, "you aren't allowed update that user's playlist") } playlist.UserID = user.ID @@ -103,7 +102,9 @@ func (c *Controller) ServeCreatePlaylist(r *http.Request) *spec.Response { if playlistPath == "" { playlistPath = playlistp.NewPath(user.ID, fmt.Sprint(time.Now().UnixMilli())) + playlistID = playlistIDEncode(playlistPath) } + if err := c.playlistStore.Write(playlistPath, &playlist); err != nil { return spec.NewError(0, "save playlist: %v", err) }