mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-26 03:49:56 +01:00
feat(library): add library ID filtering for album resources
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
ac31ea640f
commit
d44292cdc7
2 changed files with 64 additions and 1 deletions
|
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"maps"
|
||||
"slices"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
|
@ -123,6 +124,7 @@ var albumFilters = sync.OnceValue(func() map[string]filterFunc {
|
|||
"missing": booleanFilter,
|
||||
"genre_id": tagIDFilter,
|
||||
"role_total_id": allRolesFilter,
|
||||
"library_id": libraryIdFilter,
|
||||
}
|
||||
// Add all album tags as filters
|
||||
for tag := range model.AlbumLevelTags() {
|
||||
|
|
@ -183,6 +185,42 @@ func allRolesFilter(_ string, value interface{}) Sqlizer {
|
|||
return Like{"participants": fmt.Sprintf(`%%"%s"%%`, value)}
|
||||
}
|
||||
|
||||
func libraryIdFilter(field string, value interface{}) Sqlizer {
|
||||
switch v := value.(type) {
|
||||
case string:
|
||||
// Handle single library ID as string
|
||||
if libID, err := strconv.Atoi(v); err == nil {
|
||||
return Eq{"library_id": libID}
|
||||
}
|
||||
return Eq{"library_id": v}
|
||||
case int:
|
||||
return Eq{"library_id": v}
|
||||
case int64:
|
||||
return Eq{"library_id": v}
|
||||
case float64:
|
||||
return Eq{"library_id": int(v)}
|
||||
case []interface{}:
|
||||
// Handle multiple library IDs
|
||||
var ids []interface{}
|
||||
for _, id := range v {
|
||||
switch idVal := id.(type) {
|
||||
case string:
|
||||
if libID, err := strconv.Atoi(idVal); err == nil {
|
||||
ids = append(ids, libID)
|
||||
} else {
|
||||
ids = append(ids, idVal)
|
||||
}
|
||||
case int, int64, float64:
|
||||
ids = append(ids, idVal)
|
||||
}
|
||||
}
|
||||
if len(ids) > 0 {
|
||||
return Eq{"library_id": ids}
|
||||
}
|
||||
}
|
||||
return Eq{"library_id": value}
|
||||
}
|
||||
|
||||
func (r *albumRepository) CountAll(options ...model.QueryOptions) (int64, error) {
|
||||
query := r.newSelect()
|
||||
query = r.withAnnotation(query, "album.id")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue