mirror of
https://github.com/jeffvli/feishin.git
synced 2026-07-02 16:49:58 +02:00
feat(genre): support sorting by track/album count
This commit is contained in:
@@ -19,7 +19,6 @@ import {
|
||||
DeleteInternetRadioStationImageResponse,
|
||||
DeletePlaylistImageArgs,
|
||||
DeletePlaylistImageResponse,
|
||||
genreListSortMap,
|
||||
InternalControllerEndpoint,
|
||||
playlistListSortMap,
|
||||
PlaylistSongListArgs,
|
||||
@@ -596,26 +595,7 @@ export const NavidromeController: InternalControllerEndpoint = {
|
||||
};
|
||||
}
|
||||
|
||||
const res = await ndApiClient(apiClientProps).getGenreList({
|
||||
query: {
|
||||
_end: query.startIndex + (query.limit || 0),
|
||||
_order: sortOrderMap.navidrome[query.sortOrder],
|
||||
_sort: genreListSortMap.navidrome[query.sortBy],
|
||||
_start: query.startIndex,
|
||||
library_id: getLibraryId(query.musicFolderId),
|
||||
name: query.searchTerm,
|
||||
},
|
||||
});
|
||||
|
||||
if (res.status !== 200) {
|
||||
throw new Error('Failed to get genre list');
|
||||
}
|
||||
|
||||
return {
|
||||
items: res.body.data.map((genre) => ndNormalize.genre(genre, apiClientProps.server)),
|
||||
startIndex: query.startIndex || 0,
|
||||
totalRecordCount: Number(res.body.headers.get('x-total-count') || 0),
|
||||
};
|
||||
return SubsonicController.getGenreList(args);
|
||||
},
|
||||
getImageRequest: SubsonicController.getImageRequest,
|
||||
getImageUrl: SubsonicController.getImageUrl,
|
||||
|
||||
@@ -1090,9 +1090,15 @@ export const SubsonicController: InternalControllerEndpoint = {
|
||||
}
|
||||
|
||||
switch (query.sortBy) {
|
||||
case GenreListSort.ALBUM_COUNT:
|
||||
results = orderBy(results, [(v) => v.albumCount], [sortOrder]);
|
||||
break;
|
||||
case GenreListSort.NAME:
|
||||
results = orderBy(results, [(v) => v.value.toLowerCase()], [sortOrder]);
|
||||
break;
|
||||
case GenreListSort.SONG_COUNT:
|
||||
results = orderBy(results, [(v) => v.songCount], [sortOrder]);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -823,18 +823,38 @@ const GENRE_LIST_FILTERS: Partial<
|
||||
},
|
||||
],
|
||||
[ServerType.NAVIDROME]: [
|
||||
{
|
||||
defaultOrder: SortOrder.ASC,
|
||||
name: i18n.t('filter.albumCount'),
|
||||
value: GenreListSort.ALBUM_COUNT,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.ASC,
|
||||
name: i18n.t('filter.name'),
|
||||
value: GenreListSort.NAME,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.ASC,
|
||||
name: i18n.t('filter.songCount'),
|
||||
value: GenreListSort.SONG_COUNT,
|
||||
},
|
||||
],
|
||||
[ServerType.SUBSONIC]: [
|
||||
{
|
||||
defaultOrder: SortOrder.ASC,
|
||||
name: i18n.t('filter.albumCount'),
|
||||
value: GenreListSort.ALBUM_COUNT,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.ASC,
|
||||
name: i18n.t('filter.name'),
|
||||
value: GenreListSort.NAME,
|
||||
},
|
||||
{
|
||||
defaultOrder: SortOrder.ASC,
|
||||
name: i18n.t('filter.albumCount'),
|
||||
value: GenreListSort.SONG_COUNT,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
|
||||
@@ -27,7 +27,9 @@ export enum NDAlbumListSort {
|
||||
}
|
||||
|
||||
export enum NDGenreListSort {
|
||||
ALBUM_COUNT = 'albumCount',
|
||||
NAME = 'name',
|
||||
SONG_COUNT = 'songCount',
|
||||
}
|
||||
|
||||
export enum NDPlaylistListSort {
|
||||
@@ -754,6 +756,8 @@ const tag = z.object({
|
||||
const tagList = z.array(tag);
|
||||
|
||||
export enum NDTagListSort {
|
||||
ALBUM_COUNT = 'albumCount',
|
||||
SONG_COUNT = 'songCount',
|
||||
TAG_VALUE = 'tagValue',
|
||||
}
|
||||
|
||||
|
||||
@@ -155,7 +155,9 @@ export enum ExternalType {
|
||||
}
|
||||
|
||||
export enum GenreListSort {
|
||||
ALBUM_COUNT = 'albumCount',
|
||||
NAME = 'name',
|
||||
SONG_COUNT = 'songCount',
|
||||
}
|
||||
|
||||
export enum ImageType {
|
||||
@@ -166,7 +168,9 @@ export enum ImageType {
|
||||
}
|
||||
|
||||
export enum TagListSort {
|
||||
ALBUM_COUNT = 'albumCount',
|
||||
NAME = 'name',
|
||||
SONG_COUNT = 'songCount',
|
||||
}
|
||||
|
||||
export type Album = {
|
||||
@@ -430,19 +434,25 @@ type BaseEndpointArgs = {
|
||||
|
||||
type GenreListSortMap = {
|
||||
jellyfin: Record<GenreListSort, JFGenreListSort | undefined>;
|
||||
navidrome: Record<GenreListSort, NDGenreListSort | undefined>;
|
||||
subsonic: Record<UserListSort, undefined>;
|
||||
navidrome: Record<GenreListSort, NDGenreListSort>;
|
||||
subsonic: Record<GenreListSort, undefined>;
|
||||
};
|
||||
|
||||
export const genreListSortMap: GenreListSortMap = {
|
||||
jellyfin: {
|
||||
albumCount: undefined,
|
||||
name: JFGenreListSort.NAME,
|
||||
songCount: undefined,
|
||||
},
|
||||
navidrome: {
|
||||
albumCount: NDGenreListSort.NAME,
|
||||
name: NDGenreListSort.NAME,
|
||||
songCount: NDGenreListSort.NAME,
|
||||
},
|
||||
subsonic: {
|
||||
albumCount: undefined,
|
||||
name: undefined,
|
||||
songCount: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -454,13 +464,19 @@ type TagListSortMap = {
|
||||
|
||||
export const tagListSortMap: TagListSortMap = {
|
||||
jellyfin: {
|
||||
albumCount: undefined,
|
||||
name: undefined,
|
||||
songCount: undefined,
|
||||
},
|
||||
navidrome: {
|
||||
albumCount: NDTagListSort.ALBUM_COUNT,
|
||||
name: NDTagListSort.TAG_VALUE,
|
||||
songCount: NDTagListSort.SONG_COUNT,
|
||||
},
|
||||
subsonic: {
|
||||
albumCount: undefined,
|
||||
name: undefined,
|
||||
songCount: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user