mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
* feat(cmd): make artwork explain/refresh accept an id without its kind The kind can now come from the id itself: a full artwork id (al-<id>) carries it in the prefix, and a bare id is resolved across tables via GetEntityByID. The explicit <kind> <id> leader still works. * fix(cmd): keep refreshing resolvable ids when others fail to resolve resolveArtworkTargets now collects a self-describing id it cannot resolve as a failure instead of aborting, so refresh reports and skips the bad ones and still queues the rest, matching refreshItems per-item behavior. explain stays strict and rejects any unresolved input.
43 lines
1.3 KiB
Go
43 lines
1.3 KiB
Go
package model
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
)
|
|
|
|
// TODO: Should the type be encoded in the ID?
|
|
func GetEntityByID(ctx context.Context, ds DataStore, id string) (any, error) {
|
|
entity, _, err := getEntity(ctx, ds, id)
|
|
return entity, err
|
|
}
|
|
|
|
// GetEntityKindByID resolves a bare entity id to its artwork Kind, searching the same tables as
|
|
// GetEntityByID. It reports ErrNotFound when no entity owns the id.
|
|
func GetEntityKindByID(ctx context.Context, ds DataStore, id string) (Kind, error) {
|
|
_, kind, err := getEntity(ctx, ds, id)
|
|
return kind, err
|
|
}
|
|
|
|
func getEntity(ctx context.Context, ds DataStore, id string) (any, Kind, error) {
|
|
getters := []struct {
|
|
kind Kind
|
|
get func() (any, error)
|
|
}{
|
|
{KindArtistArtwork, func() (any, error) { return ds.Artist(ctx).Get(id) }},
|
|
{KindAlbumArtwork, func() (any, error) { return ds.Album(ctx).Get(id) }},
|
|
{KindPlaylistArtwork, func() (any, error) { return ds.Playlist(ctx).Get(id) }},
|
|
{KindMediaFileArtwork, func() (any, error) { return ds.MediaFile(ctx).Get(id) }},
|
|
{KindRadioArtwork, func() (any, error) { return ds.Radio(ctx).Get(id) }},
|
|
}
|
|
for _, g := range getters {
|
|
entity, err := g.get()
|
|
if err == nil {
|
|
return entity, g.kind, nil
|
|
}
|
|
if !errors.Is(err, ErrNotFound) {
|
|
return nil, Kind{}, err
|
|
}
|
|
}
|
|
return nil, Kind{}, ErrNotFound
|
|
}
|