fix(playlist): fix non-admin users not being able to create playlists (#524)
* fix(playlist): fail early if playlist path is a directory * fix(playlist): check error before assuming playlist loaded
This commit is contained in:
@@ -94,6 +94,10 @@ func (s *Store) Read(relPath string) (*Playlist, error) {
|
|||||||
return nil, fmt.Errorf("stat m3u: %w", err)
|
return nil, fmt.Errorf("stat m3u: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if stat.IsDir() {
|
||||||
|
return nil, errors.New("path is a directory")
|
||||||
|
}
|
||||||
|
|
||||||
var playlist Playlist
|
var playlist Playlist
|
||||||
playlist.UpdatedAt = stat.ModTime()
|
playlist.UpdatedAt = stat.ModTime()
|
||||||
|
|
||||||
|
|||||||
@@ -75,9 +75,11 @@ func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response
|
|||||||
playlistPath := playlistIDDecode(playlistID)
|
playlistPath := playlistIDDecode(playlistID)
|
||||||
|
|
||||||
var playlist playlistp.Playlist
|
var playlist playlistp.Playlist
|
||||||
if pl, _ := c.playlistStore.Read(playlistPath); pl != nil {
|
if playlistPath != "" {
|
||||||
|
if pl, err := c.playlistStore.Read(playlistPath); err != nil && pl != nil {
|
||||||
playlist = *pl
|
playlist = *pl
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if playlist.UserID != 0 && playlist.UserID != user.ID {
|
if playlist.UserID != 0 && playlist.UserID != user.ID {
|
||||||
return spec.NewError(50, "you aren't allowed update that user's playlist")
|
return spec.NewError(50, "you aren't allowed update that user's playlist")
|
||||||
|
|||||||
Reference in New Issue
Block a user