diff --git a/src/api/api.ts b/src/api/api.ts index ac2c958..8cca448 100644 --- a/src/api/api.ts +++ b/src/api/api.ts @@ -550,7 +550,16 @@ export const setRating = async (options: { ids: string[]; rating: number }) => { export const getSimilarSongs = async (options: { id: string; count: number }) => { const { data } = await api.get(`/getSimilarSongs2`, { params: options }); - return (data.similarSongs2.song || []).map((entry: any) => normalizeSong(entry)); + return (_.uniqBy(data.similarSongs2.song, (e: any) => e.id) || []).map((entry: any) => + normalizeSong(entry) + ); +}; + +export const getTopSongs = async (options: { artist: string; count: number }) => { + const { data } = await api.get(`/getTopSongs`, { params: options }); + return (_.uniqBy(data?.topSongs?.song, (e: any) => e.id) || []).map((entry: any) => + normalizeSong(entry) + ); }; export const updatePlaylistSongs = async (options: { id: string; entry: any[] }) => { diff --git a/src/api/controller.ts b/src/api/controller.ts index f063f4b..b9c2a59 100644 --- a/src/api/controller.ts +++ b/src/api/controller.ts @@ -22,6 +22,7 @@ import { getScanStatus, getSearch, getSimilarSongs, + getTopSongs, getStarred, scrobble, setRating, @@ -93,6 +94,7 @@ const endpoints = [ { id: 'getMusicDirectorySongs', endpoint: { subsonic: getMusicDirectorySongs, jellyfin: jfGetMusicDirectorySongs } }, { id: 'getDownloadUrl', endpoint: { subsonic: getDownloadUrl, jellyfin: jfGetDownloadUrl } }, { id: 'getSongs', endpoint: { subsonic: undefined, jellyfin: jfGetSongs } }, + { id: 'getTopSongs', endpoint: { subsonic: getTopSongs, jellyfin: undefined } }, // Playlist handling logic is split up by server type due to differences in how each server handles them. // You will need to add custom logic in the playlist/context menu component handlers. diff --git a/src/types.ts b/src/types.ts index 2b8373f..3b7ab29 100644 --- a/src/types.ts +++ b/src/types.ts @@ -51,7 +51,8 @@ export type APIEndpoints = | 'getMusicDirectory' | 'getMusicDirectorySongs' | 'getDownloadUrl' - | 'getSongs'; + | 'getSongs' + | 'getTopSongs'; export interface GenericItem { id: string;