mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-27 21:18:49 +01:00
feat: enhance library management with refresh event broadcasting
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
340192693e
commit
dc264a64db
3 changed files with 16 additions and 2 deletions
|
|
@ -18,6 +18,7 @@ import (
|
|||
"github.com/navidrome/navidrome/model"
|
||||
"github.com/navidrome/navidrome/model/request"
|
||||
"github.com/navidrome/navidrome/server/events"
|
||||
"github.com/navidrome/navidrome/utils/slice"
|
||||
)
|
||||
|
||||
// Scanner interface for triggering scans
|
||||
|
|
@ -92,7 +93,18 @@ func (s *libraryService) SetUserLibraries(ctx context.Context, userID string, li
|
|||
}
|
||||
}
|
||||
|
||||
return s.ds.User(ctx).SetUserLibraries(userID, libraryIDs)
|
||||
// Set user libraries
|
||||
err = s.ds.User(ctx).SetUserLibraries(userID, libraryIDs)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error setting user libraries: %w", err)
|
||||
}
|
||||
|
||||
// Send refresh event to all clients
|
||||
event := &events.RefreshResource{}
|
||||
libIDs := slice.Map(libraryIDs, func(id int) string { return strconv.Itoa(id) })
|
||||
event = event.With("user", userID).With("library", libIDs...)
|
||||
s.broker.SendBroadcastMessage(ctx, event)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *libraryService) ValidateLibraryAccess(ctx context.Context, userID string, libraryID int) error {
|
||||
|
|
|
|||
|
|
@ -75,6 +75,8 @@ type UserRepository interface {
|
|||
// Library association methods
|
||||
GetUserLibraries(userID string) (Libraries, error)
|
||||
SetUserLibraries(userID string, libraryIDs []int) error
|
||||
|
||||
// TODO Remove these methods in favor of SetUserLibraries
|
||||
AddUserLibrary(userID string, libraryID int) error
|
||||
RemoveUserLibrary(userID string, libraryID int) error
|
||||
}
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ const LibrarySelector = () => {
|
|||
|
||||
// Reload user libraries when library changes occur
|
||||
useRefreshOnEvents({
|
||||
events: ['library'],
|
||||
events: ['library', 'user'],
|
||||
onRefresh: loadUserLibraries,
|
||||
})
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue