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:
Nadia Santalla
2024-09-15 16:57:23 +02:00
committed by GitHub
parent bcb613c79c
commit ac798ac2d2
2 changed files with 8 additions and 2 deletions

View File

@@ -94,6 +94,10 @@ func (s *Store) Read(relPath string) (*Playlist, error) {
return nil, fmt.Errorf("stat m3u: %w", err)
}
if stat.IsDir() {
return nil, errors.New("path is a directory")
}
var playlist Playlist
playlist.UpdatedAt = stat.ModTime()

View File

@@ -75,8 +75,10 @@ func (c *Controller) ServeCreateOrUpdatePlaylist(r *http.Request) *spec.Response
playlistPath := playlistIDDecode(playlistID)
var playlist playlistp.Playlist
if pl, _ := c.playlistStore.Read(playlistPath); pl != nil {
playlist = *pl
if playlistPath != "" {
if pl, err := c.playlistStore.Read(playlistPath); err != nil && pl != nil {
playlist = *pl
}
}
if playlist.UserID != 0 && playlist.UserID != user.ID {