Use first admin user for all scan operations
This commit is contained in:
@@ -93,9 +93,7 @@ func (s *playlistSync) parsePlaylist(ctx context.Context, playlistFile string, b
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *playlistSync) updatePlaylistIfNewer(ctx context.Context, newPls *model.Playlist) error {
|
func (s *playlistSync) updatePlaylistIfNewer(ctx context.Context, newPls *model.Playlist) error {
|
||||||
owner := s.getPlaylistsOwner(ctx)
|
owner, _ := request.UsernameFrom(ctx)
|
||||||
ctx = request.WithUsername(ctx, owner.UserName)
|
|
||||||
ctx = request.WithUser(ctx, *owner)
|
|
||||||
|
|
||||||
pls, err := s.ds.Playlist(ctx).FindByPath(newPls.Path)
|
pls, err := s.ds.Playlist(ctx).FindByPath(newPls.Path)
|
||||||
if err != nil && err != model.ErrNotFound {
|
if err != nil && err != model.ErrNotFound {
|
||||||
@@ -113,16 +111,8 @@ func (s *playlistSync) updatePlaylistIfNewer(ctx context.Context, newPls *model.
|
|||||||
newPls.Comment = pls.Comment
|
newPls.Comment = pls.Comment
|
||||||
newPls.Owner = pls.Owner
|
newPls.Owner = pls.Owner
|
||||||
} else {
|
} else {
|
||||||
log.Info(ctx, "Adding synced playlist", "playlist", newPls.Name, "path", newPls.Path, "owner", owner.UserName)
|
log.Info(ctx, "Adding synced playlist", "playlist", newPls.Name, "path", newPls.Path, "owner", owner)
|
||||||
newPls.Owner = owner.UserName
|
newPls.Owner = owner
|
||||||
}
|
}
|
||||||
return s.ds.Playlist(ctx).Put(newPls)
|
return s.ds.Playlist(ctx).Put(newPls)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *playlistSync) getPlaylistsOwner(ctx context.Context) *model.User {
|
|
||||||
u, err := s.ds.User(ctx).FindFirstAdmin()
|
|
||||||
if err != nil {
|
|
||||||
log.Error(ctx, "Error retrieving playlist owner", err)
|
|
||||||
}
|
|
||||||
return u
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
|
|
||||||
"github.com/deluan/navidrome/log"
|
"github.com/deluan/navidrome/log"
|
||||||
"github.com/deluan/navidrome/model"
|
"github.com/deluan/navidrome/model"
|
||||||
|
"github.com/deluan/navidrome/model/request"
|
||||||
"github.com/deluan/navidrome/utils"
|
"github.com/deluan/navidrome/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -44,6 +45,8 @@ func NewTagScanner2(rootFolder string, ds model.DataStore) *TagScanner2 {
|
|||||||
// refresh the collected albums and artists with the metadata from the mediafiles
|
// refresh the collected albums and artists with the metadata from the mediafiles
|
||||||
// Delete all empty albums, delete all empty Artists
|
// Delete all empty albums, delete all empty Artists
|
||||||
func (s *TagScanner2) Scan(ctx context.Context, lastModifiedSince time.Time) error {
|
func (s *TagScanner2) Scan(ctx context.Context, lastModifiedSince time.Time) error {
|
||||||
|
ctx = s.setAdminUser(ctx)
|
||||||
|
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
allDirs, err := s.getDirTree(ctx)
|
allDirs, err := s.getDirTree(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -321,3 +324,14 @@ func (s *TagScanner2) loadTracks(filePaths []string) (model.MediaFiles, error) {
|
|||||||
}
|
}
|
||||||
return mfs, nil
|
return mfs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *TagScanner2) setAdminUser(ctx context.Context) context.Context {
|
||||||
|
u, err := s.ds.User(ctx).FindFirstAdmin()
|
||||||
|
if err != nil {
|
||||||
|
log.Error(ctx, "Error retrieving playlist owner", err)
|
||||||
|
u = &model.User{}
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx = request.WithUsername(ctx, u.UserName)
|
||||||
|
return request.WithUser(ctx, *u)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user