mirror of
https://github.com/antebudimir/feishin.git
synced 2026-01-01 10:23:33 +00:00
Support genres in context menu
This commit is contained in:
parent
0b207c78e7
commit
d0aba6e16e
12 changed files with 182 additions and 56 deletions
|
|
@ -112,7 +112,7 @@ const getGenreList = async (args: GenreListArgs): Promise<GenreListResponse> =>
|
|||
}
|
||||
|
||||
return {
|
||||
items: res.body.data,
|
||||
items: res.body.data.map((genre) => ndNormalize.genre(genre)),
|
||||
startIndex: query.startIndex || 0,
|
||||
totalRecordCount: Number(res.body.headers.get('x-total-count') || 0),
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,9 +1,18 @@
|
|||
import { nanoid } from 'nanoid';
|
||||
import { Song, LibraryItem, Album, Playlist, User, AlbumArtist } from '/@/renderer/api/types';
|
||||
import {
|
||||
Song,
|
||||
LibraryItem,
|
||||
Album,
|
||||
Playlist,
|
||||
User,
|
||||
AlbumArtist,
|
||||
Genre,
|
||||
} from '/@/renderer/api/types';
|
||||
import { ServerListItem, ServerType } from '/@/renderer/types';
|
||||
import z from 'zod';
|
||||
import { ndType } from './navidrome-types';
|
||||
import { ssType } from '/@/renderer/api/subsonic/subsonic-types';
|
||||
import { NDGenre } from '/@/renderer/api/navidrome.types';
|
||||
|
||||
const getImageUrl = (args: { url: string | null }) => {
|
||||
const { url } = args;
|
||||
|
|
@ -81,7 +90,12 @@ const normalizeSong = (
|
|||
createdAt: item.createdAt.split('T')[0],
|
||||
discNumber: item.discNumber,
|
||||
duration: item.duration,
|
||||
genres: item.genres,
|
||||
genres: item.genres?.map((genre) => ({
|
||||
id: genre.id,
|
||||
imageUrl: null,
|
||||
itemType: LibraryItem.GENRE,
|
||||
name: genre.name,
|
||||
})),
|
||||
id,
|
||||
imagePlaceholderUrl,
|
||||
imageUrl,
|
||||
|
|
@ -130,7 +144,12 @@ const normalizeAlbum = (
|
|||
backdropImageUrl: imageBackdropUrl,
|
||||
createdAt: item.createdAt.split('T')[0],
|
||||
duration: item.duration * 1000 || null,
|
||||
genres: item.genres,
|
||||
genres: item.genres?.map((genre) => ({
|
||||
id: genre.id,
|
||||
imageUrl: null,
|
||||
itemType: LibraryItem.GENRE,
|
||||
name: genre.name,
|
||||
})),
|
||||
id: item.id,
|
||||
imagePlaceholderUrl,
|
||||
imageUrl,
|
||||
|
|
@ -166,7 +185,12 @@ const normalizeAlbumArtist = (
|
|||
backgroundImageUrl: null,
|
||||
biography: item.biography || null,
|
||||
duration: null,
|
||||
genres: item.genres,
|
||||
genres: item.genres?.map((genre) => ({
|
||||
id: genre.id,
|
||||
imageUrl: null,
|
||||
itemType: LibraryItem.GENRE,
|
||||
name: genre.name,
|
||||
})),
|
||||
id: item.id,
|
||||
imageUrl: imageUrl || null,
|
||||
itemType: LibraryItem.ALBUM_ARTIST,
|
||||
|
|
@ -222,6 +246,17 @@ const normalizePlaylist = (
|
|||
};
|
||||
};
|
||||
|
||||
const normalizeGenre = (item: NDGenre): Genre => {
|
||||
return {
|
||||
albumCount: undefined,
|
||||
id: item.id,
|
||||
imageUrl: null,
|
||||
itemType: LibraryItem.GENRE,
|
||||
name: item.name,
|
||||
songCount: undefined,
|
||||
};
|
||||
};
|
||||
|
||||
const normalizeUser = (item: z.infer<typeof ndType._response.user>): User => {
|
||||
return {
|
||||
createdAt: item.createdAt,
|
||||
|
|
@ -237,6 +272,7 @@ const normalizeUser = (item: z.infer<typeof ndType._response.user>): User => {
|
|||
export const ndNormalize = {
|
||||
album: normalizeAlbum,
|
||||
albumArtist: normalizeAlbumArtist,
|
||||
genre: normalizeGenre,
|
||||
playlist: normalizePlaylist,
|
||||
song: normalizeSong,
|
||||
user: normalizeUser,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue