Add favorite/rating table columns

This commit is contained in:
jeffvli 2023-01-06 00:39:49 -08:00
parent d1dfbaedaa
commit ab031820f6
12 changed files with 158 additions and 29 deletions

View file

@ -63,6 +63,7 @@ import {
albumArtistListSortMap,
UpdatePlaylistArgs,
UpdatePlaylistResponse,
LibraryItem,
} from '/@/renderer/api/types';
import { useAuthStore } from '/@/renderer/store';
import { ServerListItem, ServerType } from '/@/renderer/types';
@ -652,7 +653,7 @@ const normalizeSong = (
id: item.Id,
imagePlaceholderUrl: null,
imageUrl: getSongCoverArtUrl({ baseUrl: server.url, item, size: imageSize || 300 }),
isFavorite: (item.UserData && item.UserData.IsFavorite) || false,
itemType: LibraryItem.SONG,
lastPlayedAt: null,
name: item.Name,
path: (item.MediaSources && item.MediaSources[0]?.Path) || null,
@ -661,6 +662,7 @@ const normalizeSong = (
releaseDate: null,
releaseYear: (item.ProductionYear && String(item.ProductionYear)) || null,
serverId: server.id,
serverType: ServerType.JELLYFIN,
size: item.MediaSources && item.MediaSources[0]?.Size,
streamUrl: getStreamUrl({
container: item.MediaSources[0]?.Container,
@ -671,9 +673,10 @@ const normalizeSong = (
server,
}),
trackNumber: item.IndexNumber,
type: ServerType.JELLYFIN,
uniqueId: nanoid(),
updatedAt: item.DateCreated,
userFavorite: (item.UserData && item.UserData.IsFavorite) || false,
userRating: null,
};
};
@ -697,19 +700,21 @@ const normalizeAlbum = (item: JFAlbum, server: ServerListItem, imageSize?: numbe
size: imageSize || 300,
}),
isCompilation: null,
isFavorite: item.UserData?.IsFavorite || false,
itemType: LibraryItem.ALBUM,
lastPlayedAt: null,
name: item.Name,
playCount: item.UserData?.PlayCount || 0,
rating: null,
releaseDate: item.PremiereDate?.split('T')[0] || null,
releaseYear: item.ProductionYear,
serverId: server.id,
serverType: ServerType.JELLYFIN,
size: null,
songCount: item?.ChildCount || null,
songs: item.songs?.map((song) => normalizeSong(song, server, '', imageSize)),
uniqueId: nanoid(),
updatedAt: item?.DateLastMediaAdded || item.DateCreated,
userFavorite: item.UserData?.IsFavorite || false,
userRating: null,
};
};
@ -730,12 +735,15 @@ const normalizeAlbumArtist = (
item,
size: imageSize || 300,
}),
isFavorite: item.UserData.IsFavorite || false,
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: null,
name: item.Name,
playCount: item.UserData.PlayCount,
rating: null,
serverId: server.id,
serverType: ServerType.JELLYFIN,
songCount: null,
userFavorite: item.UserData.IsFavorite || false,
userRating: null,
};
};
@ -759,11 +767,14 @@ const normalizePlaylist = (
id: item.Id,
imagePlaceholderUrl,
imageUrl: imageUrl || null,
itemType: LibraryItem.PLAYLIST,
name: item.Name,
owner: null,
ownerId: null,
public: null,
rules: null,
serverId: server.id,
serverType: ServerType.JELLYFIN,
size: null,
songCount: item?.ChildCount || null,
sync: null,

View file

@ -72,6 +72,7 @@ import {
albumListSortMap,
sortOrderMap,
User,
LibraryItem,
} from '/@/renderer/api/types';
import { toast } from '/@/renderer/components/toast';
import { useAuthStore } from '/@/renderer/store';
@ -526,7 +527,7 @@ const normalizeSong = (
id,
imagePlaceholderUrl,
imageUrl,
isFavorite: item.starred,
itemType: LibraryItem.SONG,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate,
name: item.title,
path: item.path,
@ -534,12 +535,14 @@ const normalizeSong = (
releaseDate: new Date(item.year, 0, 1).toISOString(),
releaseYear: String(item.year),
serverId: server.id,
serverType: ServerType.NAVIDROME,
size: item.size,
streamUrl: `${server.url}/rest/stream.view?id=${id}&v=1.13.0&c=feishin_${deviceId}&${server.credential}`,
trackNumber: item.trackNumber,
type: ServerType.NAVIDROME,
uniqueId: nanoid(),
updatedAt: item.updatedAt,
userFavorite: item.starred || false,
userRating: item.rating || null,
};
};
@ -566,25 +569,25 @@ const normalizeAlbum = (item: NDAlbum, server: ServerListItem, imageSize?: numbe
imagePlaceholderUrl,
imageUrl,
isCompilation: item.compilation,
isFavorite: item.starred,
itemType: LibraryItem.ALBUM,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate,
name: item.name,
playCount: item.playCount,
rating: item.rating,
releaseDate: new Date(item.minYear, 0, 1).toISOString(),
releaseYear: item.minYear,
serverId: server.id,
serverType: ServerType.NAVIDROME,
size: item.size,
songCount: item.songCount,
songs: item.songs ? item.songs.map((song) => normalizeSong(song, server, '')) : undefined,
uniqueId: nanoid(),
updatedAt: item.updatedAt,
userFavorite: item.starred,
userRating: item.rating,
};
};
const normalizeAlbumArtist = (item: NDAlbumArtist): AlbumArtist => {
console.log('item :>> ', item);
const normalizeAlbumArtist = (item: NDAlbumArtist, server: ServerListItem): AlbumArtist => {
return {
albumCount: item.albumCount,
backgroundImageUrl: null,
@ -593,12 +596,15 @@ const normalizeAlbumArtist = (item: NDAlbumArtist): AlbumArtist => {
genres: item.genres,
id: item.id,
imageUrl: item.largeImageUrl || null,
isFavorite: item.starred,
itemType: LibraryItem.ALBUM_ARTIST,
lastPlayedAt: item.playDate.includes('0001-') ? null : item.playDate,
name: item.name,
playCount: item.playCount,
rating: item.rating,
serverId: server.id,
serverType: ServerType.NAVIDROME,
songCount: item.songCount,
userFavorite: item.starred,
userRating: item.rating,
};
};
@ -623,11 +629,14 @@ const normalizePlaylist = (
id: item.id,
imagePlaceholderUrl,
imageUrl,
itemType: LibraryItem.PLAYLIST,
name: item.name,
owner: item.ownerName,
ownerId: item.ownerId,
public: item.public,
rules: item?.rules || null,
serverId: server.id,
serverType: ServerType.NAVIDROME,
size: item.size,
songCount: item.songCount,
sync: item.sync,

View file

@ -161,7 +161,9 @@ const albumArtistList = (
);
break;
case 'navidrome':
albumArtists = data?.items.map((item) => ndNormalize.albumArtist(item as NDAlbumArtist));
albumArtists = data?.items.map((item) =>
ndNormalize.albumArtist(item as NDAlbumArtist, server),
);
break;
case 'subsonic':
break;

View file

@ -163,19 +163,21 @@ export type Album = {
imagePlaceholderUrl: string | null;
imageUrl: string | null;
isCompilation: boolean | null;
isFavorite: boolean;
itemType: LibraryItem.ALBUM;
lastPlayedAt: string | null;
name: string;
playCount: number | null;
rating: number | null;
releaseDate: string | null;
releaseYear: number | null;
serverId: string;
serverType: ServerType;
size: number | null;
songCount: number | null;
songs?: Song[];
uniqueId: string;
updatedAt: string;
userFavorite: boolean;
userRating: number | null;
} & { songs?: Song[] };
export type Song = {
@ -197,7 +199,7 @@ export type Song = {
id: string;
imagePlaceholderUrl: string | null;
imageUrl: string | null;
isFavorite: boolean;
itemType: LibraryItem.SONG;
lastPlayedAt: string | null;
name: string;
path: string | null;
@ -205,12 +207,14 @@ export type Song = {
releaseDate: string | null;
releaseYear: string | null;
serverId: string;
serverType: ServerType;
size: number;
streamUrl: string;
trackNumber: number;
type: ServerType;
uniqueId: string;
updatedAt: string;
userFavorite: boolean;
userRating: number | null;
};
export type AlbumArtist = {
@ -221,12 +225,15 @@ export type AlbumArtist = {
genres: Genre[];
id: string;
imageUrl: string | null;
isFavorite: boolean;
itemType: LibraryItem.ALBUM_ARTIST;
lastPlayedAt: string | null;
name: string;
playCount: number | null;
rating: number | null;
serverId: string;
serverType: ServerType;
songCount: number | null;
userFavorite: boolean;
userRating: number | null;
};
export type RelatedAlbumArtist = {
@ -238,9 +245,12 @@ export type Artist = {
biography: string | null;
createdAt: string;
id: string;
itemType: LibraryItem.ARTIST;
name: string;
remoteCreatedAt: string | null;
serverFolderId: string;
serverId: string;
serverType: ServerType;
updatedAt: string;
};
@ -261,11 +271,14 @@ export type Playlist = {
id: string;
imagePlaceholderUrl: string | null;
imageUrl: string | null;
itemType: LibraryItem.PLAYLIST;
name: string;
owner: string | null;
ownerId: string | null;
public: boolean | null;
rules?: Record<string, any> | null;
serverId: string;
serverType: ServerType;
size: number | null;
songCount: number | null;
sync?: boolean | null;