Skip to content

Commit

Permalink
fix(playlist): return new playlist id for createPlaylist
Browse files Browse the repository at this point in the history
fixes #464
  • Loading branch information
sentriz committed Feb 2, 2024
1 parent 29c5397 commit 314e963
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion server/ctrlsubsonic/ctrl.go
Expand Up @@ -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)))
Expand Down
7 changes: 4 additions & 3 deletions server/ctrlsubsonic/handlers_playlist.go
Expand Up @@ -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)

Expand All @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit 314e963

Please sign in to comment.