Skip to content

Commit

Permalink
properly implement Jellyfin getSongDetail (#298)
Browse files Browse the repository at this point in the history
  • Loading branch information
kgarner7 authored Oct 17, 2023
1 parent c7aa5d0 commit 5fdf4c0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/renderer/api/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/api/jellyfin/jellyfin-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions src/renderer/api/jellyfin/jellyfin-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -940,6 +942,23 @@ const getLyrics = async (args: LyricsArgs): Promise<LyricsResponse> => {
return res.body.Lyrics.map((lyric) => [lyric.Start! / 1e4, lyric.Text]);
};

const getSongDetail = async (args: SongDetailArgs): Promise<SongDetailResponse> => {
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,
Expand All @@ -959,6 +978,7 @@ export const jfController = {
getPlaylistList,
getPlaylistSongList,
getRandomSongList,
getSongDetail,
getSongList,
getTopSongList,
removeFromPlaylist,
Expand Down

1 comment on commit 5fdf4c0

@vercel
Copy link

@vercel vercel bot commented on 5fdf4c0 Oct 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

feishin – ./

feishin.vercel.app
feishin-jeffvli.vercel.app
feishin-git-development-jeffvli.vercel.app

Please sign in to comment.