mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-26 03:49:56 +01:00
feat(jellyfin): filter items by year and record label (#5817)
* feat(persistence): add AlbumRepository.GetYears for distinct album years * test(persistence): verify GetYears de-duplicates repeated years Regression test that adds two albums with the same non-zero max_year (2005) and verifies that GetYears() returns that year exactly once, ensuring the SQL DISTINCT clause is applied correctly. Catches any future removal of DISTINCT from the GetYears query. * feat(jellyfin): add legacy /Items/Filters endpoint (genres + years) * feat(jellyfin): add /Studios endpoint from record label tags * refactor(persistence): drop duplicate columns in tagRepository.GetAll * fix(jellyfin): exclude missing albums from filter years GetYears only filtered max_year > 0, so albums whose files were all removed (missing=true, kept when Scanner.PurgeMissing=never) contributed stale years to /Items/Filters. Filter them out like the normal album listings do. Also return an empty slice from the MockAlbumRepo to match the real repository. * feat(jellyfin): filter /Items by Years= * feat(jellyfin): filter /Items by StudioIds= (record labels) * feat(jellyfin): scope filter and studio lists to ParentId library * refactor(jellyfin): extract parentIDScope and libraryScopeFilter helpers Collapse the three inline resolveLibraryScope(dto.DecodeID(parentid)) call sites and the duplicated empty-scope guard into two small helpers, so the empty-scope=unrestricted contract lives in one place. Reuse the existing names() helper in the Years= e2e test. * feat(jellyfin): expose record labels as album Studios Add a Studios field to the album BaseItemDto, populated from the record-label tags and gated behind Fields=Studios (matching Jellyfin's ItemFields convention). Studio ids reuse the record-label tag identity, so they round-trip with the /Studios list and the StudioIds= filter. Real Jellyfin leaves Studios empty for music; Feishin reads it as the album's record label.
This commit is contained in:
parent
b27d6f61ae
commit
5927e693d1
22 changed files with 435 additions and 26 deletions
|
|
@ -209,4 +209,11 @@ func (m *MockAlbumRepo) SetStar(starred bool, itemIDs ...string) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (m *MockAlbumRepo) GetYears(libraryIDs ...int) ([]int, error) {
|
||||
if m.Err {
|
||||
return nil, errors.New("error")
|
||||
}
|
||||
return []int{}, nil
|
||||
}
|
||||
|
||||
var _ model.AlbumRepository = (*MockAlbumRepo)(nil)
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func (db *MockDataStore) Tag(ctx context.Context) model.TagRepository {
|
|||
if db.RealDS != nil {
|
||||
return db.RealDS.Tag(ctx)
|
||||
}
|
||||
db.MockedTag = struct{ model.TagRepository }{}
|
||||
db.MockedTag = &MockTagRepo{}
|
||||
return db.MockedTag
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,9 @@ import (
|
|||
)
|
||||
|
||||
type MockedGenreRepo struct {
|
||||
Error error
|
||||
Data map[string]model.Genre
|
||||
Error error
|
||||
Data map[string]model.Genre
|
||||
Options model.QueryOptions
|
||||
}
|
||||
|
||||
func (r *MockedGenreRepo) init() {
|
||||
|
|
@ -15,7 +16,10 @@ func (r *MockedGenreRepo) init() {
|
|||
}
|
||||
}
|
||||
|
||||
func (r *MockedGenreRepo) GetAll(...model.QueryOptions) (model.Genres, error) {
|
||||
func (r *MockedGenreRepo) GetAll(options ...model.QueryOptions) (model.Genres, error) {
|
||||
if len(options) > 0 {
|
||||
r.Options = options[0]
|
||||
}
|
||||
if r.Error != nil {
|
||||
return nil, r.Error
|
||||
}
|
||||
|
|
|
|||
24
tests/mock_tag_repo.go
Normal file
24
tests/mock_tag_repo.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package tests
|
||||
|
||||
import (
|
||||
"github.com/navidrome/navidrome/model"
|
||||
)
|
||||
|
||||
// MockTagRepo records the QueryOptions passed to GetAll, mirroring MockArtistRepo, so tests can
|
||||
// assert on which filters a caller attached (e.g. a library scope).
|
||||
type MockTagRepo struct {
|
||||
model.TagRepository
|
||||
Data model.TagList
|
||||
Options model.QueryOptions
|
||||
Err error
|
||||
}
|
||||
|
||||
func (r *MockTagRepo) GetAll(_ model.TagName, options ...model.QueryOptions) (model.TagList, error) {
|
||||
if len(options) > 0 {
|
||||
r.Options = options[0]
|
||||
}
|
||||
if r.Err != nil {
|
||||
return nil, r.Err
|
||||
}
|
||||
return r.Data, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue