refactor domain types to rename itemType

This commit is contained in:
jeffvli
2025-11-13 22:04:00 -08:00
parent 173e00af3d
commit 164332d752
9 changed files with 54 additions and 40 deletions
+17 -9
View File
@@ -227,6 +227,7 @@ const normalizeSong = (
}
return {
_itemType: LibraryItem.SONG,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
album: item.Album,
@@ -265,15 +266,16 @@ const normalizeSong = (
}
: null,
genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name,
})),
id: item.Id,
imagePlaceholderUrl: null,
imageUrl: getSongCoverArtUrl({ baseUrl: server?.url || '', item, size: imageSize || 100 }),
itemType: LibraryItem.SONG,
lastPlayedAt: null,
lyrics: null,
mbzRecordingId: null,
@@ -307,6 +309,7 @@ const normalizeAlbum = (
imageSize?: number,
): Album => {
return {
_itemType: LibraryItem.ALBUM,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
albumArtist: item.AlbumArtist,
@@ -327,9 +330,11 @@ const normalizeAlbum = (
duration: item.RunTimeTicks / 10000,
explicitStatus: null,
genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name,
})),
id: item.Id,
@@ -340,7 +345,6 @@ const normalizeAlbum = (
size: imageSize || 300,
}),
isCompilation: null,
itemType: LibraryItem.ALBUM,
lastPlayedAt: null,
mbzId: item.ProviderIds?.MusicBrainzAlbum || null,
name: item.Name,
@@ -383,6 +387,7 @@ const normalizeAlbumArtist = (
) || [];
return {
_itemType: LibraryItem.ALBUM_ARTIST,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
albumCount: item.AlbumCount ?? null,
@@ -390,9 +395,11 @@ const normalizeAlbumArtist = (
biography: item.Overview || null,
duration: item.RunTimeTicks / 10000,
genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name,
})),
id: item.Id,
@@ -401,7 +408,6 @@ const normalizeAlbumArtist = (
item,
size: imageSize || 300,
}),
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: null,
mbz: item.ProviderIds?.MusicBrainzArtist || null,
name: item.Name,
@@ -427,20 +433,22 @@ const normalizePlaylist = (
const imagePlaceholderUrl = null;
return {
_itemType: LibraryItem.PLAYLIST,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
description: item.Overview || null,
duration: item.RunTimeTicks / 10000,
genres: item.GenreItems?.map((entry) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
id: entry.Id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: entry.Name,
})),
id: item.Id,
imagePlaceholderUrl,
imageUrl: imageUrl || null,
itemType: LibraryItem.PLAYLIST,
name: item.Name,
owner: null,
ownerId: null,
@@ -504,12 +512,12 @@ const normalizeGenre = (
server: null | ServerListItem,
): Genre => {
return {
_itemType: LibraryItem.GENRE,
_serverId: server?.id || '',
_serverType: ServerType.JELLYFIN,
albumCount: undefined,
id: item.Id,
imageUrl: getGenreCoverArtUrl({ baseUrl: server?.url || '', item, size: 200 }),
itemType: LibraryItem.GENRE,
name: item.Name,
songCount: undefined,
};
@@ -151,6 +151,7 @@ const normalizeSong = (
album: item.album,
albumId: item.albumId,
...getArtists(item),
_itemType: LibraryItem.SONG,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
artistName: item.artist,
@@ -176,15 +177,16 @@ const normalizeSong = (
? { album: item.rgAlbumGain, track: item.rgTrackGain }
: null,
genres: (item.genres || []).map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
id: genre.id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name,
})),
id,
imagePlaceholderUrl,
imageUrl,
itemType: LibraryItem.SONG,
lastPlayedAt: normalizePlayDate(item),
lyrics: item.lyrics ? item.lyrics : null,
mbzRecordingId: item.mbzReleaseTrackId || null,
@@ -278,6 +280,7 @@ const normalizeAlbum = (
return {
...parseAlbumTags(item),
...getArtists(item),
_itemType: LibraryItem.ALBUM,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
albumArtist: item.albumArtist,
@@ -292,17 +295,18 @@ const normalizeAlbum = (
? ExplicitStatus.CLEAN
: null,
genres: (item.genres || []).map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
id: genre.id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name,
})),
id: item.id,
imagePlaceholderUrl,
imageUrl,
isCompilation: item.compilation,
itemType: LibraryItem.ALBUM,
isCompilation: item.compilation,
lastPlayedAt: normalizePlayDate(item),
mbzId: item.mbzAlbumId || null,
name: item.name,
@@ -363,6 +367,7 @@ const normalizeAlbumArtist = (
}
return {
_itemType: LibraryItem.ALBUM_ARTIST,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
albumCount,
@@ -370,14 +375,15 @@ const normalizeAlbumArtist = (
biography: item.biography || null,
duration: null,
genres: (item.genres || []).map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
id: genre.id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name,
})),
id: item.id,
imageUrl: imageUrl || null,
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: normalizePlayDate(item),
mbz: item.mbzArtistId || null,
name: item.name,
@@ -410,6 +416,7 @@ const normalizePlaylist = (
const imagePlaceholderUrl = null;
return {
_itemType: LibraryItem.PLAYLIST,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
description: item.comment,
@@ -418,7 +425,6 @@ const normalizePlaylist = (
id: item.id,
imagePlaceholderUrl,
imageUrl,
itemType: LibraryItem.PLAYLIST,
name: item.name,
owner: item.ownerName,
ownerId: item.ownerId,
@@ -435,12 +441,12 @@ const normalizeGenre = (
server: null | ServerListItem,
): Genre => {
return {
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.NAVIDROME,
albumCount: undefined,
id: item.id,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: item.name,
songCount: undefined,
};
@@ -98,21 +98,21 @@ const getGenres = (
): Genre[] => {
return item.genres
? item.genres.map((genre) => ({
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
id: genre.name,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: genre.name,
}))
: item.genre
? [
{
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
id: item.genre,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: item.genre,
},
]
@@ -135,6 +135,7 @@ const normalizeSong = (
const streamUrl = `${server?.url}/rest/stream.view?id=${item.id}&v=1.13.0&c=Feishin&${server?.credential}`;
return {
_itemType: LibraryItem.SONG,
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
album: item.album || '',
@@ -170,7 +171,6 @@ const normalizeSong = (
id: item.id.toString(),
imagePlaceholderUrl: null,
imageUrl,
itemType: LibraryItem.SONG,
lastPlayedAt: null,
lyrics: null,
mbzRecordingId: item.musicBrainzId || null,
@@ -215,6 +215,7 @@ const normalizeAlbumArtist = (
}) || null;
return {
_itemType: LibraryItem.ALBUM_ARTIST,
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
albumCount: item.albumCount ? Number(item.albumCount) : 0,
@@ -224,7 +225,6 @@ const normalizeAlbumArtist = (
genres: [],
id: item.id.toString(),
imageUrl,
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: null,
mbz: null,
name: item.name,
@@ -250,6 +250,7 @@ const normalizeAlbum = (
}) || null;
return {
_itemType: LibraryItem.ALBUM,
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
albumArtist: item.artist,
@@ -270,7 +271,6 @@ const normalizeAlbum = (
imagePlaceholderUrl: null,
imageUrl,
isCompilation: null,
itemType: LibraryItem.ALBUM,
lastPlayedAt: null,
mbzId: null,
name: item.name,
@@ -302,6 +302,7 @@ const normalizePlaylist = (
server?: null | ServerListItemWithCredential,
): Playlist => {
return {
_itemType: LibraryItem.PLAYLIST,
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
description: item.comment || null,
@@ -315,7 +316,6 @@ const normalizePlaylist = (
credential: server?.credential,
size: 300,
}),
itemType: LibraryItem.PLAYLIST,
name: item.name,
owner: item.owner,
ownerId: item.owner,
@@ -330,12 +330,12 @@ const normalizeGenre = (
server: null | ServerListItemWithCredential,
): Genre => {
return {
_itemType: LibraryItem.GENRE,
_serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC,
albumCount: item.albumCount,
id: item.value,
imageUrl: null,
itemType: LibraryItem.GENRE,
name: item.value,
songCount: item.songCount,
};