refactor Genre domain type to include serverType and serverId

This commit is contained in:
jeffvli
2025-11-13 21:50:11 -08:00
parent 4f1d39d3c4
commit 173e00af3d
6 changed files with 25 additions and 6 deletions
@@ -370,7 +370,7 @@ export const NavidromeController: InternalControllerEndpoint = {
}
return {
items: res.body.data.map((genre) => ndNormalize.genre(genre)),
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),
};
@@ -647,7 +647,7 @@ export const SubsonicController: InternalControllerEndpoint = {
break;
}
const genres = results.map(ssNormalize.genre);
const genres = results.map((genre) => ssNormalize.genre(genre, apiClientProps.server));
return {
items: genres,
@@ -504,6 +504,8 @@ const normalizeGenre = (
server: null | ServerListItem,
): Genre => {
return {
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
albumCount: undefined,
id: item.Id,
imageUrl: getGenreCoverArtUrl({ baseUrl: server?.url || '', item, size: 200 }),
@@ -430,8 +430,13 @@ const normalizePlaylist = (
};
};
const normalizeGenre = (item: z.infer<typeof ndType._response.genre>): Genre => {
const normalizeGenre = (
item: z.infer<typeof ndType._response.genre>,
server: null | ServerListItem,
): Genre => {
return {
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
albumCount: undefined,
id: item.id,
imageUrl: null,
+13 -3
View File
@@ -94,9 +94,12 @@ const getGenres = (
| z.infer<typeof ssType._response.album>
| z.infer<typeof ssType._response.albumListEntry>
| z.infer<typeof ssType._response.song>,
server?: null | ServerListItemWithCredential,
): Genre[] => {
return item.genres
? item.genres.map((genre) => ({
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
id: genre.name,
imageUrl: null,
itemType: LibraryItem.GENRE,
@@ -105,6 +108,8 @@ const getGenres = (
: item.genre
? [
{
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
id: item.genre,
imageUrl: null,
itemType: LibraryItem.GENRE,
@@ -161,7 +166,7 @@ const normalizeSong = (
track: item.replayGain.trackGain,
}
: null,
genres: getGenres(item),
genres: getGenres(item, server),
id: item.id.toString(),
imagePlaceholderUrl: null,
imageUrl,
@@ -260,7 +265,7 @@ const normalizeAlbum = (
: item.explicitStatus === 'clean'
? ExplicitStatus.CLEAN
: null,
genres: getGenres(item),
genres: getGenres(item, server),
id: item.id.toString(),
imagePlaceholderUrl: null,
imageUrl,
@@ -320,8 +325,13 @@ const normalizePlaylist = (
};
};
const normalizeGenre = (item: z.infer<typeof ssType._response.genre>): Genre => {
const normalizeGenre = (
item: z.infer<typeof ssType._response.genre>,
server: null | ServerListItemWithCredential,
): Genre => {
return {
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
albumCount: item.albumCount,
id: item.value,
imageUrl: null,
+2
View File
@@ -262,6 +262,8 @@ export type GainInfo = {
};
export type Genre = {
_serverId: string;
_serverType: ServerType;
albumCount?: number;
id: string;
imageUrl: null | string;