Do not panic if when updatePlaylist is called with a non-existent ID.
Fix #2876
This commit is contained in:
+6
-2
@@ -231,13 +231,17 @@ func (s *playlists) Update(ctx context.Context, playlistID string,
|
|||||||
var pls *model.Playlist
|
var pls *model.Playlist
|
||||||
var err error
|
var err error
|
||||||
repo := tx.Playlist(ctx)
|
repo := tx.Playlist(ctx)
|
||||||
|
tracks := repo.Tracks(playlistID, true)
|
||||||
|
if tracks == nil {
|
||||||
|
return fmt.Errorf("%w: playlist '%s'", model.ErrNotFound, playlistID)
|
||||||
|
}
|
||||||
if needsTrackRefresh {
|
if needsTrackRefresh {
|
||||||
pls, err = repo.GetWithTracks(playlistID, true)
|
pls, err = repo.GetWithTracks(playlistID, true)
|
||||||
pls.RemoveTracks(idxToRemove)
|
pls.RemoveTracks(idxToRemove)
|
||||||
pls.AddTracks(idsToAdd)
|
pls.AddTracks(idsToAdd)
|
||||||
} else {
|
} else {
|
||||||
if len(idsToAdd) > 0 {
|
if len(idsToAdd) > 0 {
|
||||||
_, err = repo.Tracks(playlistID, true).Add(idsToAdd)
|
_, err = tracks.Add(idsToAdd)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -264,7 +268,7 @@ func (s *playlists) Update(ctx context.Context, playlistID string,
|
|||||||
}
|
}
|
||||||
// Special case: The playlist is now empty
|
// Special case: The playlist is now empty
|
||||||
if len(idxToRemove) > 0 && len(pls.Tracks) == 0 {
|
if len(idxToRemove) > 0 && len(pls.Tracks) == 0 {
|
||||||
if err = repo.Tracks(playlistID, true).DeleteAll(); err != nil {
|
if err = tracks.DeleteAll(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ func (r *playlistRepository) Tracks(playlistId string, refreshSmartPlaylist bool
|
|||||||
|
|
||||||
pls, err := r.Get(playlistId)
|
pls, err := r.Get(playlistId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(r.ctx, "Error getting playlist's tracks - THIS SHOULD NOT HAPPEN!", "playlistId", playlistId, err)
|
log.Warn(r.ctx, "Error getting playlist's tracks", "playlistId", playlistId, err)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if refreshSmartPlaylist {
|
if refreshSmartPlaylist {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func (api *Router) getPlaylist(ctx context.Context, id string) (*responses.Subso
|
|||||||
pls, err := api.ds.Playlist(ctx).GetWithTracks(id, true)
|
pls, err := api.ds.Playlist(ctx).GetWithTracks(id, true)
|
||||||
if errors.Is(err, model.ErrNotFound) {
|
if errors.Is(err, model.ErrNotFound) {
|
||||||
log.Error(ctx, err.Error(), "id", id)
|
log.Error(ctx, err.Error(), "id", id)
|
||||||
return nil, newError(responses.ErrorDataNotFound, "Directory not found")
|
return nil, newError(responses.ErrorDataNotFound, "playlist not found")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(ctx, err)
|
log.Error(ctx, err)
|
||||||
@@ -150,7 +150,7 @@ func (api *Router) UpdatePlaylist(r *http.Request) (*responses.Subsonic, error)
|
|||||||
return nil, newError(responses.ErrorAuthorizationFail)
|
return nil, newError(responses.ErrorAuthorizationFail)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(r, err)
|
log.Error(r, "Error updating playlist", "id", playlistId, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return newResponse(), nil
|
return newResponse(), nil
|
||||||
|
|||||||
Reference in New Issue
Block a user