fix missing normalizations for subsonic imageId (#1449)

This commit is contained in:
jeffvli
2025-12-26 14:04:04 -08:00
parent bb3cb4a6ad
commit fb8245539f
+14 -63
View File
@@ -16,28 +16,6 @@ import {
Song, Song,
} from '/@/shared/types/domain-types'; } from '/@/shared/types/domain-types';
const getCoverArtUrl = (args: {
baseUrl: string | undefined;
coverArtId?: string;
credential: string | undefined;
size: number;
}) => {
const size = args.size ? args.size : 250;
if (!args.coverArtId || args.coverArtId.match('2a96cbd8b46e442fc41c2b86b821562f')) {
return null;
}
return (
`${args.baseUrl}/rest/getCoverArt.view` +
`?id=${args.coverArtId}` +
`&${args.credential}` +
'&v=1.13.0' +
'&c=Feishin' +
`&size=${size}`
);
};
const getArtistList = ( const getArtistList = (
artists?: typeof ssType._response.song._type.artists, artists?: typeof ssType._response.song._type.artists,
artistId?: number | string, artistId?: number | string,
@@ -46,12 +24,14 @@ const getArtistList = (
return artists return artists
? artists.map((item) => ({ ? artists.map((item) => ({
id: item.id.toString(), id: item.id.toString(),
imageId: null,
imageUrl: null, imageUrl: null,
name: item.name, name: item.name,
})) }))
: [ : [
{ {
id: artistId?.toString() || '', id: artistId?.toString() || '',
imageId: null,
imageUrl: null, imageUrl: null,
name: artistName || '', name: artistName || '',
}, },
@@ -72,6 +52,7 @@ const getParticipants = (
for (const contributor of item.contributors) { for (const contributor of item.contributors) {
const artist = { const artist = {
id: contributor.artist.id?.toString() || '', id: contributor.artist.id?.toString() || '',
imageId: null,
imageUrl: null, imageUrl: null,
name: contributor.artist.name || '', name: contributor.artist.name || '',
}; };
@@ -105,6 +86,7 @@ const getGenres = (
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
albumCount: null, albumCount: null,
id: genre.name, id: genre.name,
imageId: null,
imageUrl: null, imageUrl: null,
name: genre.name, name: genre.name,
songCount: null, songCount: null,
@@ -117,6 +99,7 @@ const getGenres = (
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
albumCount: null, albumCount: null,
id: item.genre, id: item.genre,
imageId: null,
imageUrl: null, imageUrl: null,
name: item.genre, name: item.genre,
songCount: null, songCount: null,
@@ -128,16 +111,7 @@ const getGenres = (
const normalizeSong = ( const normalizeSong = (
item: z.infer<typeof ssType._response.song>, item: z.infer<typeof ssType._response.song>,
server?: null | ServerListItemWithCredential, server?: null | ServerListItemWithCredential,
size?: number,
): Song => { ): Song => {
const imageUrl =
getCoverArtUrl({
baseUrl: server?.url,
coverArtId: item.coverArt?.toString(),
credential: server?.credential,
size: size || 300,
}) || null;
return { return {
_itemType: LibraryItem.SONG, _itemType: LibraryItem.SONG,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
@@ -173,8 +147,8 @@ const normalizeSong = (
: null, : null,
genres: getGenres(item, server), genres: getGenres(item, server),
id: item.id.toString(), id: item.id.toString(),
imagePlaceholderUrl: null, imageId: item.coverArt?.toString() || null,
imageUrl, imageUrl: null,
lastPlayedAt: null, lastPlayedAt: null,
lyrics: null, lyrics: null,
mbzRecordingId: item.musicBrainzId || null, mbzRecordingId: item.musicBrainzId || null,
@@ -207,27 +181,18 @@ const normalizeAlbumArtist = (
| z.infer<typeof ssType._response.albumArtist> | z.infer<typeof ssType._response.albumArtist>
| z.infer<typeof ssType._response.artistListEntry>, | z.infer<typeof ssType._response.artistListEntry>,
server?: null | ServerListItemWithCredential, server?: null | ServerListItemWithCredential,
imageSize?: number,
): AlbumArtist => { ): AlbumArtist => {
const imageUrl =
getCoverArtUrl({
baseUrl: server?.url,
coverArtId: item.coverArt?.toString(),
credential: server?.credential,
size: imageSize || 100,
}) || null;
return { return {
_itemType: LibraryItem.ALBUM_ARTIST, _itemType: LibraryItem.ALBUM_ARTIST,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
albumCount: item.albumCount ? Number(item.albumCount) : 0, albumCount: item.albumCount ? Number(item.albumCount) : 0,
backgroundImageUrl: null,
biography: null, biography: null,
duration: null, duration: null,
genres: [], genres: [],
id: item.id.toString(), id: item.id.toString(),
imageUrl, imageId: item.coverArt?.toString() || null,
imageUrl: null,
lastPlayedAt: null, lastPlayedAt: null,
mbz: null, mbz: null,
name: item.name, name: item.name,
@@ -242,16 +207,7 @@ const normalizeAlbumArtist = (
const normalizeAlbum = ( const normalizeAlbum = (
item: z.infer<typeof ssType._response.album> | z.infer<typeof ssType._response.albumListEntry>, item: z.infer<typeof ssType._response.album> | z.infer<typeof ssType._response.albumListEntry>,
server?: null | ServerListItemWithCredential, server?: null | ServerListItemWithCredential,
imageSize?: number,
): Album => { ): Album => {
const imageUrl =
getCoverArtUrl({
baseUrl: server?.url,
coverArtId: item.coverArt?.toString(),
credential: server?.credential,
size: imageSize || 300,
}) || null;
return { return {
_itemType: LibraryItem.ALBUM, _itemType: LibraryItem.ALBUM,
_serverId: server?.id || 'unknown', _serverId: server?.id || 'unknown',
@@ -259,7 +215,6 @@ const normalizeAlbum = (
albumArtist: item.artist, albumArtist: item.artist,
albumArtists: getArtistList(item.artists, item.artistId, item.artist), albumArtists: getArtistList(item.artists, item.artistId, item.artist),
artists: [], artists: [],
backdropImageUrl: null,
comment: null, comment: null,
createdAt: item.created, createdAt: item.created,
duration: item.duration * 1000, duration: item.duration * 1000,
@@ -271,8 +226,8 @@ const normalizeAlbum = (
: null, : null,
genres: getGenres(item, server), genres: getGenres(item, server),
id: item.id.toString(), id: item.id.toString(),
imagePlaceholderUrl: null, imageId: item.coverArt?.toString() || null,
imageUrl, imageUrl: null,
isCompilation: null, isCompilation: null,
lastPlayedAt: null, lastPlayedAt: null,
mbzId: null, mbzId: null,
@@ -322,13 +277,8 @@ const normalizePlaylist = (
duration: item.duration * 1000, duration: item.duration * 1000,
genres: [], genres: [],
id: item.id.toString(), id: item.id.toString(),
imagePlaceholderUrl: null, imageId: item.coverArt?.toString() || null,
imageUrl: getCoverArtUrl({ imageUrl: null,
baseUrl: server?.url,
coverArtId: item.coverArt?.toString(),
credential: server?.credential,
size: 300,
}),
name: item.name, name: item.name,
owner: item.owner, owner: item.owner,
ownerId: item.owner, ownerId: item.owner,
@@ -348,6 +298,7 @@ const normalizeGenre = (
_serverType: ServerType.SUBSONIC, _serverType: ServerType.SUBSONIC,
albumCount: item.albumCount, albumCount: item.albumCount,
id: item.value, id: item.value,
imageId: null,
imageUrl: null, imageUrl: null,
name: item.value, name: item.value,
songCount: item.songCount, songCount: item.songCount,