diff --git a/src/api/controller.ts b/src/api/controller.ts index aa60fd2..6a1f67c 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -42,6 +42,8 @@ import { getPlaylists as jfGetPlaylists, getRandomSongs as jfGetRandomSongs, getStarred as jfGetStarred, + star as jfStar, + unstar as jfUnstar, } from './jellyfinApi'; import { APIEndpoints, ServerType } from '../types'; @@ -58,8 +60,8 @@ const endpoints = [ { id: 'getArtistSongs', endpoint: { subsonic: getArtistSongs, jellyfin: jfGetArtistSongs } }, { id: 'startScan', endpoint: { subsonic: startScan, jellyfin: undefined } }, { id: 'getScanStatus', endpoint: { subsonic: getScanStatus, jellyfin: undefined } }, - { id: 'star', endpoint: { subsonic: star, jellyfin: undefined } }, - { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: undefined } }, + { id: 'star', endpoint: { subsonic: star, jellyfin: jfStar } }, + { id: 'unstar', endpoint: { subsonic: unstar, jellyfin: jfUnstar } }, { id: 'batchStar', endpoint: { subsonic: batchStar, jellyfin: undefined } }, { id: 'batchUnstar', endpoint: { subsonic: batchUnstar, jellyfin: undefined } }, { id: 'setRating', endpoint: { subsonic: setRating, jellyfin: undefined } }, diff --git a/src/api/jellyfinApi.ts b/src/api/jellyfinApi.ts index 4ffff44..ba82e78 100644 --- a/src/api/jellyfinApi.ts +++ b/src/api/jellyfinApi.ts @@ -107,7 +107,7 @@ const normalizeSong = (item: any) => { created: item.DateCreated, streamUrl: getStreamUrl(item.Id), image: getCoverArtUrl(item, 150), - starred: item.UserData.isFavorite ? 'true' : undefined, + starred: item.UserData && item.UserData.IsFavorite ? 'true' : undefined, type: Item.Music, uniqueId: nanoid(), }; @@ -377,3 +377,13 @@ export const getStarred = async () => { artist: (artistData.Items || []).map((entry: any) => normalizeArtist(entry)), }; }; + +export const star = async (options: { id: string }) => { + const { data } = await jellyfinApi.post(`/users/${auth.username}/favoriteitems/${options.id}`); + return data; +}; + +export const unstar = async (options: { id: string }) => { + const { data } = await jellyfinApi.delete(`/users/${auth.username}/favoriteitems/${options.id}`); + return data; +}; diff --git a/src/components/dashboard/Dashboard.tsx b/src/components/dashboard/Dashboard.tsx index 808a4fc..c4cd040 100644 --- a/src/components/dashboard/Dashboard.tsx +++ b/src/components/dashboard/Dashboard.tsx @@ -84,7 +84,7 @@ const Dashboard = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); dispatch(setStar({ id: [rowData.id], type: 'star' })); queryClient.setQueryData(['recentAlbums', musicFolder], (oldData: any) => { @@ -123,7 +123,7 @@ const Dashboard = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); dispatch(setStar({ id: [rowData.id], type: 'unstar' })); queryClient.setQueryData(['recentAlbums', musicFolder], (oldData: any) => { diff --git a/src/components/library/AlbumList.tsx b/src/components/library/AlbumList.tsx index d561a0c..4f4dc73 100644 --- a/src/components/library/AlbumList.tsx +++ b/src/components/library/AlbumList.tsx @@ -156,7 +156,7 @@ const AlbumList = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['albumList', album.active.filter, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); @@ -170,7 +170,7 @@ const AlbumList = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['albumList', album.active.filter, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); diff --git a/src/components/library/AlbumView.tsx b/src/components/library/AlbumView.tsx index efc1bac..44e8abc 100644 --- a/src/components/library/AlbumView.tsx +++ b/src/components/library/AlbumView.tsx @@ -150,7 +150,7 @@ const AlbumView = ({ ...rest }: any) => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: data.id, type: 'album' } : null, + args: { id: data.id, type: 'album' }, }); queryClient.setQueryData(['album', id], { ...data, starred: Date.now() }); } else { @@ -168,7 +168,7 @@ const AlbumView = ({ ...rest }: any) => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'star' })); queryClient.setQueryData(['album', id], (oldData: any) => { @@ -183,7 +183,7 @@ const AlbumView = ({ ...rest }: any) => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'unstar' })); queryClient.setQueryData(['album', id], (oldData: any) => { diff --git a/src/components/library/ArtistList.tsx b/src/components/library/ArtistList.tsx index 8605d71..d3d40a2 100644 --- a/src/components/library/ArtistList.tsx +++ b/src/components/library/ArtistList.tsx @@ -88,7 +88,7 @@ const ArtistList = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null, + args: { id: rowData.id, type: 'artist' }, }); queryClient.setQueryData(['artistList', musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); @@ -102,7 +102,7 @@ const ArtistList = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null, + args: { id: rowData.id, type: 'artist' }, }); queryClient.setQueryData(['artistList', musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData, { id: rowData.id })); diff --git a/src/components/library/ArtistView.tsx b/src/components/library/ArtistView.tsx index b151b63..f6cf062 100644 --- a/src/components/library/ArtistView.tsx +++ b/src/components/library/ArtistView.tsx @@ -46,7 +46,7 @@ import { StyledButton, StyledPopover, StyledTag } from '../shared/styled'; import { setStatus } from '../../redux/playerSlice'; import { GradientBackground, PageHeaderSubtitleDataLine } from '../layout/styled'; import { apiController } from '../../api/controller'; -import { Artist, GenericItem, Server } from '../../types'; +import { Artist, GenericItem } from '../../types'; const fac = new FastAverageColor(); @@ -106,14 +106,14 @@ const ArtistView = ({ ...rest }: any) => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: data.id, type: 'artist' } : null, + args: { id: data.id, type: 'artist' }, }); queryClient.setQueryData(['artist', artistId], { ...data, starred: Date.now() }); } else { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: data.id, type: 'artist' } : null, + args: { id: data.id, type: 'artist' }, }); queryClient.setQueryData(['artist', artistId], { ...data, starred: undefined }); } @@ -162,7 +162,7 @@ const ArtistView = ({ ...rest }: any) => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['artist', artistId], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData?.album, { id: rowData.id })); @@ -176,7 +176,7 @@ const ArtistView = ({ ...rest }: any) => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['artist', artistId], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData?.album, { id: rowData.id })); diff --git a/src/components/library/FolderList.tsx b/src/components/library/FolderList.tsx index 4b70704..989f77d 100644 --- a/src/components/library/FolderList.tsx +++ b/src/components/library/FolderList.tsx @@ -118,7 +118,7 @@ const FolderList = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['folder', folder.currentViewedFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.child, { id: rowData.id })); @@ -132,7 +132,7 @@ const FolderList = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['folder', folder.currentViewedFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.child, { id: rowData.id })); diff --git a/src/components/player/NowPlayingMiniView.tsx b/src/components/player/NowPlayingMiniView.tsx index 99aa11c..9d3096b 100644 --- a/src/components/player/NowPlayingMiniView.tsx +++ b/src/components/player/NowPlayingMiniView.tsx @@ -265,14 +265,14 @@ const NowPlayingMiniView = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'star' })); } else { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'unstar' })); } diff --git a/src/components/player/NowPlayingView.tsx b/src/components/player/NowPlayingView.tsx index b8f5244..e0fa9d3 100644 --- a/src/components/player/NowPlayingView.tsx +++ b/src/components/player/NowPlayingView.tsx @@ -60,7 +60,7 @@ import { } from '../../shared/utils'; import { notifyToast } from '../shared/toast'; import { apiController } from '../../api/controller'; -import { Server, Song } from '../../types'; +import { Song } from '../../types'; const NowPlayingView = () => { const tableRef = useRef(); @@ -275,14 +275,14 @@ const NowPlayingView = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'star' })); } else { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'unstar' })); } diff --git a/src/components/player/PlayerBar.tsx b/src/components/player/PlayerBar.tsx index c021756..da181b6 100644 --- a/src/components/player/PlayerBar.tsx +++ b/src/components/player/PlayerBar.tsx @@ -35,7 +35,6 @@ import { CoverArtWrapper } from '../layout/styled'; import { getCurrentEntryList, isCached } from '../../shared/utils'; import { StyledPopover } from '../shared/styled'; import { apiController } from '../../api/controller'; -import { Server } from '../../types'; const PlayerBar = () => { const queryClient = useQueryClient(); @@ -278,10 +277,7 @@ const PlayerBar = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: - config.serverType === Server.Subsonic - ? { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' } - : null, + args: { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' }, }); dispatch( setStar({ @@ -293,10 +289,7 @@ const PlayerBar = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: - config.serverType === Server.Subsonic - ? { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' } - : null, + args: { id: playQueue[currentEntryList][playQueue.currentIndex].id, type: 'music' }, }); dispatch( setStar({ diff --git a/src/components/playlist/PlaylistView.tsx b/src/components/playlist/PlaylistView.tsx index 1c81595..df4197a 100644 --- a/src/components/playlist/PlaylistView.tsx +++ b/src/components/playlist/PlaylistView.tsx @@ -352,7 +352,7 @@ const PlaylistView = ({ ...rest }) => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'star' })); dispatch(setPlaylistStar({ id: [rowData.id], type: 'star' })); @@ -369,7 +369,7 @@ const PlaylistView = ({ ...rest }) => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'unstar' })); dispatch(setPlaylistStar({ id: [rowData.id], type: 'unstar' })); diff --git a/src/components/search/SearchView.tsx b/src/components/search/SearchView.tsx index 908891c..8653b2a 100644 --- a/src/components/search/SearchView.tsx +++ b/src/components/search/SearchView.tsx @@ -94,7 +94,7 @@ const SearchView = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.song, { id: rowData.id })); @@ -108,7 +108,7 @@ const SearchView = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.song, { id: rowData.id })); @@ -126,7 +126,7 @@ const SearchView = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null, + args: { id: rowData.id, type: 'artist' }, }); queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.artist, { id: rowData.id })); @@ -140,7 +140,7 @@ const SearchView = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.artist, { id: rowData.id })); @@ -158,7 +158,7 @@ const SearchView = () => { await apiController({ serverType: config.serverType, endpoint: 'star', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null, + args: { id: rowData.id, type: 'artist' }, }); queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.album, { id: rowData.id })); @@ -172,7 +172,7 @@ const SearchView = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); queryClient.setQueryData(['search', urlQuery, musicFolder], (oldData: any) => { const starredIndices = _.keys(_.pickBy(oldData.album, { id: rowData.id })); diff --git a/src/components/starred/StarredView.tsx b/src/components/starred/StarredView.tsx index 063ed77..18b471b 100644 --- a/src/components/starred/StarredView.tsx +++ b/src/components/starred/StarredView.tsx @@ -106,7 +106,7 @@ const StarredView = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'music' } : null, + args: { id: rowData.id, type: 'music' }, }); dispatch(setStar({ id: [rowData.id], type: 'unstar' })); await queryClient.refetchQueries(['starred', musicFolder], { @@ -118,7 +118,7 @@ const StarredView = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'album' } : null, + args: { id: rowData.id, type: 'album' }, }); await queryClient.refetchQueries(['starred', musicFolder], { active: true, @@ -129,7 +129,7 @@ const StarredView = () => { await apiController({ serverType: config.serverType, endpoint: 'unstar', - args: config.serverType === Server.Subsonic ? { id: rowData.id, type: 'artist' } : null, + args: { id: rowData.id, type: 'artist' }, }); await queryClient.refetchQueries(['starred', musicFolder], { active: true,