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