From 5fdf4c06f9618d5047c4626019379ddbf6e813ad Mon Sep 17 00:00:00 2001 From: Kendall Garner <17521368+kgarner7@users.noreply.github.com> Date: Tue, 17 Oct 2023 23:05:44 +0000 Subject: [PATCH] properly implement Jellyfin getSongDetail (#298) --- src/renderer/api/controller.ts | 2 +- src/renderer/api/jellyfin/jellyfin-api.ts | 2 +- .../api/jellyfin/jellyfin-controller.ts | 20 +++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/renderer/api/controller.ts b/src/renderer/api/controller.ts index ea6ce7887..90b360a48 100644 --- a/src/renderer/api/controller.ts +++ b/src/renderer/api/controller.ts @@ -128,7 +128,7 @@ const endpoints: ApiController = { getPlaylistList: jfController.getPlaylistList, getPlaylistSongList: jfController.getPlaylistSongList, getRandomSongList: jfController.getRandomSongList, - getSongDetail: undefined, + getSongDetail: jfController.getSongDetail, getSongList: jfController.getSongList, getTopSongs: jfController.getTopSongList, getUserList: undefined, diff --git a/src/renderer/api/jellyfin/jellyfin-api.ts b/src/renderer/api/jellyfin/jellyfin-api.ts index 12237410f..7ce4b6c36 100644 --- a/src/renderer/api/jellyfin/jellyfin-api.ts +++ b/src/renderer/api/jellyfin/jellyfin-api.ts @@ -160,7 +160,7 @@ export const contract = c.router({ }, getSongDetail: { method: 'GET', - path: 'song/:id', + path: 'users/:userId/items/:id', responses: { 200: jfType._response.song, 400: jfType._response.error, diff --git a/src/renderer/api/jellyfin/jellyfin-controller.ts b/src/renderer/api/jellyfin/jellyfin-controller.ts index 472f1ee72..d73efff7d 100644 --- a/src/renderer/api/jellyfin/jellyfin-controller.ts +++ b/src/renderer/api/jellyfin/jellyfin-controller.ts @@ -47,6 +47,8 @@ import { LyricsArgs, LyricsResponse, genreListSortMap, + SongDetailArgs, + SongDetailResponse, } from '/@/renderer/api/types'; import { jfApiClient } from '/@/renderer/api/jellyfin/jellyfin-api'; import { jfNormalize } from './jellyfin-normalize'; @@ -940,6 +942,23 @@ const getLyrics = async (args: LyricsArgs): Promise => { return res.body.Lyrics.map((lyric) => [lyric.Start! / 1e4, lyric.Text]); }; +const getSongDetail = async (args: SongDetailArgs): Promise => { + const { query, apiClientProps } = args; + + const res = await jfApiClient(apiClientProps).getSongDetail({ + params: { + id: query.id, + userId: apiClientProps.server?.userId ?? '', + }, + }); + + if (res.status !== 200) { + throw new Error('Failed to get song detail'); + } + + return jfNormalize.song(res.body, apiClientProps.server, ''); +}; + export const jfController = { addToPlaylist, authenticate, @@ -959,6 +978,7 @@ export const jfController = { getPlaylistList, getPlaylistSongList, getRandomSongList, + getSongDetail, getSongList, getTopSongList, removeFromPlaylist,