mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-07 04:20:12 +02:00
Additional refactor to api and types
This commit is contained in:
@@ -7,7 +7,7 @@ import type {
|
||||
SongDetailArgs,
|
||||
AlbumArtistDetailArgs,
|
||||
AlbumArtistListArgs,
|
||||
RatingArgs,
|
||||
SetRatingArgs,
|
||||
GenreListArgs,
|
||||
CreatePlaylistArgs,
|
||||
DeletePlaylistArgs,
|
||||
@@ -79,8 +79,8 @@ export type ControllerEndpoint = Partial<{
|
||||
getUserList: (args: UserListArgs) => Promise<UserListResponse>;
|
||||
removeFromPlaylist: (args: RemoveFromPlaylistArgs) => Promise<RemoveFromPlaylistResponse>;
|
||||
scrobble: (args: ScrobbleArgs) => Promise<ScrobbleResponse>;
|
||||
setRating: (args: SetRatingArgs) => Promise<RatingResponse>;
|
||||
updatePlaylist: (args: UpdatePlaylistArgs) => Promise<UpdatePlaylistResponse>;
|
||||
updateRating: (args: RatingArgs) => Promise<RatingResponse>;
|
||||
}>;
|
||||
|
||||
type ApiController = {
|
||||
@@ -119,8 +119,8 @@ const endpoints: ApiController = {
|
||||
getUserList: undefined,
|
||||
removeFromPlaylist: jellyfinApi.removeFromPlaylist,
|
||||
scrobble: jellyfinApi.scrobble,
|
||||
setRating: undefined,
|
||||
updatePlaylist: jellyfinApi.updatePlaylist,
|
||||
updateRating: undefined,
|
||||
},
|
||||
navidrome: {
|
||||
addToPlaylist: ndController.addToPlaylist,
|
||||
@@ -151,8 +151,8 @@ const endpoints: ApiController = {
|
||||
getUserList: ndController.getUserList,
|
||||
removeFromPlaylist: ndController.removeFromPlaylist,
|
||||
scrobble: ssController.scrobble,
|
||||
setRating: ssController.setRating,
|
||||
updatePlaylist: ndController.updatePlaylist,
|
||||
updateRating: ssController.setRating,
|
||||
},
|
||||
subsonic: {
|
||||
clearPlaylist: undefined,
|
||||
@@ -180,8 +180,8 @@ const endpoints: ApiController = {
|
||||
getTopSongs: ssController.getTopSongList,
|
||||
getUserList: undefined,
|
||||
scrobble: ssController.scrobble,
|
||||
setRating: undefined,
|
||||
updatePlaylist: undefined,
|
||||
updateRating: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -286,8 +286,8 @@ const deleteFavorite = async (args: FavoriteArgs) => {
|
||||
return (apiController('deleteFavorite') as ControllerEndpoint['deleteFavorite'])?.(args);
|
||||
};
|
||||
|
||||
const updateRating = async (args: RatingArgs) => {
|
||||
return (apiController('updateRating') as ControllerEndpoint['updateRating'])?.(args);
|
||||
const updateRating = async (args: SetRatingArgs) => {
|
||||
return (apiController('setRating') as ControllerEndpoint['setRating'])?.(args);
|
||||
};
|
||||
|
||||
const getTopSongList = async (args: TopSongListArgs) => {
|
||||
@@ -295,7 +295,7 @@ const getTopSongList = async (args: TopSongListArgs) => {
|
||||
};
|
||||
|
||||
const scrobble = async (args: ScrobbleArgs) => {
|
||||
return (apiController('scrobble', args.server) as ControllerEndpoint['scrobble'])?.(args);
|
||||
return (apiController('scrobble') as ControllerEndpoint['scrobble'])?.(args);
|
||||
};
|
||||
|
||||
export const controller = {
|
||||
|
||||
@@ -278,10 +278,7 @@ const createPlaylist = async (args: CreatePlaylistArgs): Promise<CreatePlaylistR
|
||||
throw new Error('Failed to create playlist');
|
||||
}
|
||||
|
||||
return {
|
||||
id: res.body.data.id,
|
||||
name: body.name,
|
||||
};
|
||||
return null;
|
||||
};
|
||||
|
||||
const updatePlaylist = async (args: UpdatePlaylistArgs): Promise<UpdatePlaylistResponse> => {
|
||||
@@ -304,9 +301,7 @@ const updatePlaylist = async (args: UpdatePlaylistArgs): Promise<UpdatePlaylistR
|
||||
throw new Error('Failed to update playlist');
|
||||
}
|
||||
|
||||
return {
|
||||
id: res.body.data.id,
|
||||
};
|
||||
return null;
|
||||
};
|
||||
|
||||
const deletePlaylist = async (args: DeletePlaylistArgs): Promise<DeletePlaylistResponse> => {
|
||||
|
||||
@@ -730,11 +730,10 @@ export type FavoriteResponse = null | undefined;
|
||||
|
||||
export type FavoriteQuery = {
|
||||
id: string[];
|
||||
serverId: string;
|
||||
type: LibraryItem;
|
||||
};
|
||||
|
||||
export type FavoriteArgs = { query: FavoriteQuery } & BaseEndpointArgs;
|
||||
export type FavoriteArgs = { query: FavoriteQuery; serverId: string } & BaseEndpointArgs;
|
||||
|
||||
// Rating
|
||||
export type RatingResponse = null | undefined;
|
||||
@@ -742,10 +741,9 @@ export type RatingResponse = null | undefined;
|
||||
export type RatingQuery = {
|
||||
item: AnyLibraryItems;
|
||||
rating: number;
|
||||
serverId: string;
|
||||
};
|
||||
|
||||
export type SetRatingArgs = { query: RatingQuery } & BaseEndpointArgs;
|
||||
export type SetRatingArgs = { query: RatingQuery; serverId: string } & BaseEndpointArgs;
|
||||
|
||||
// Add to playlist
|
||||
export type AddToPlaylistResponse = null | undefined;
|
||||
@@ -761,6 +759,7 @@ export type AddToPlaylistBody = {
|
||||
export type AddToPlaylistArgs = {
|
||||
body: AddToPlaylistBody;
|
||||
query: AddToPlaylistQuery;
|
||||
serverId: string;
|
||||
} & BaseEndpointArgs;
|
||||
|
||||
// Remove from playlist
|
||||
@@ -771,10 +770,13 @@ export type RemoveFromPlaylistQuery = {
|
||||
songId: string[];
|
||||
};
|
||||
|
||||
export type RemoveFromPlaylistArgs = { query: RemoveFromPlaylistQuery } & BaseEndpointArgs;
|
||||
export type RemoveFromPlaylistArgs = {
|
||||
query: RemoveFromPlaylistQuery;
|
||||
serverId: string;
|
||||
} & BaseEndpointArgs;
|
||||
|
||||
// Create Playlist
|
||||
export type CreatePlaylistResponse = { id: string; name: string };
|
||||
export type CreatePlaylistResponse = null | undefined;
|
||||
|
||||
export type CreatePlaylistBody = {
|
||||
_custom?: {
|
||||
@@ -790,10 +792,10 @@ export type CreatePlaylistBody = {
|
||||
name: string;
|
||||
};
|
||||
|
||||
export type CreatePlaylistArgs = { body: CreatePlaylistBody } & BaseEndpointArgs;
|
||||
export type CreatePlaylistArgs = { body: CreatePlaylistBody; serverId: string } & BaseEndpointArgs;
|
||||
|
||||
// Update Playlist
|
||||
export type UpdatePlaylistResponse = { id: string };
|
||||
export type UpdatePlaylistResponse = null | undefined;
|
||||
|
||||
export type UpdatePlaylistQuery = {
|
||||
id: string;
|
||||
@@ -817,6 +819,7 @@ export type UpdatePlaylistBody = {
|
||||
export type UpdatePlaylistArgs = {
|
||||
body: UpdatePlaylistBody;
|
||||
query: UpdatePlaylistQuery;
|
||||
serverId: string;
|
||||
} & BaseEndpointArgs;
|
||||
|
||||
// Delete Playlist
|
||||
@@ -824,7 +827,10 @@ export type DeletePlaylistResponse = null | undefined;
|
||||
|
||||
export type DeletePlaylistQuery = { id: string };
|
||||
|
||||
export type DeletePlaylistArgs = { query: DeletePlaylistQuery } & BaseEndpointArgs;
|
||||
export type DeletePlaylistArgs = {
|
||||
query: DeletePlaylistQuery;
|
||||
serverId: string;
|
||||
} & BaseEndpointArgs;
|
||||
|
||||
// Playlist List
|
||||
export type PlaylistListResponse = BasePaginatedResponse<Playlist[]>;
|
||||
@@ -980,6 +986,7 @@ export type ScrobbleResponse = null | undefined;
|
||||
|
||||
export type ScrobbleArgs = {
|
||||
query: ScrobbleQuery;
|
||||
serverId: string;
|
||||
} & BaseEndpointArgs;
|
||||
|
||||
export type ScrobbleQuery = {
|
||||
|
||||
Reference in New Issue
Block a user