Add missing elements from Navidrome API
This commit is contained in:
parent
70c62c8b52
commit
52049ce163
2 changed files with 54 additions and 6 deletions
|
@ -66,6 +66,7 @@ export const contract = c.router({
|
||||||
getAlbumList: {
|
getAlbumList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'album',
|
path: 'album',
|
||||||
|
query: ndType._parameters.albumList,
|
||||||
responses: {
|
responses: {
|
||||||
200: resultWithHeaders(ndType._response.albumList),
|
200: resultWithHeaders(ndType._response.albumList),
|
||||||
},
|
},
|
||||||
|
@ -87,10 +88,19 @@ export const contract = c.router({
|
||||||
getPlaylistList: {
|
getPlaylistList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'playlist',
|
path: 'playlist',
|
||||||
|
query: ndType._parameters.playlistList,
|
||||||
responses: {
|
responses: {
|
||||||
200: resultWithHeaders(ndType._response.playlistList),
|
200: resultWithHeaders(ndType._response.playlistList),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
getPlaylistSongList: {
|
||||||
|
method: 'GET',
|
||||||
|
path: 'playlist/:id/tracks',
|
||||||
|
query: ndType._parameters.songList,
|
||||||
|
responses: {
|
||||||
|
200: resultWithHeaders(ndType._response.playlistSongList),
|
||||||
|
},
|
||||||
|
},
|
||||||
getSongDetail: {
|
getSongDetail: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'song/:id',
|
path: 'song/:id',
|
||||||
|
@ -109,6 +119,7 @@ export const contract = c.router({
|
||||||
getUserList: {
|
getUserList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'user',
|
path: 'user',
|
||||||
|
query: ndType._parameters.userList,
|
||||||
responses: {
|
responses: {
|
||||||
200: resultWithHeaders(ndType._response.userList),
|
200: resultWithHeaders(ndType._response.userList),
|
||||||
},
|
},
|
||||||
|
@ -164,7 +175,9 @@ axiosClient.interceptors.response.use(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
export const ndApiClient = (server: ServerListItem | string) => {
|
export const ndApiClient = (args: { server: ServerListItem | string; signal?: AbortSignal }) => {
|
||||||
|
const { server, signal } = args;
|
||||||
|
|
||||||
return initClient(contract, {
|
return initClient(contract, {
|
||||||
api: async ({ path, method, headers, body }) => {
|
api: async ({ path, method, headers, body }) => {
|
||||||
let baseUrl: string | undefined;
|
let baseUrl: string | undefined;
|
||||||
|
@ -186,6 +199,7 @@ export const ndApiClient = (server: ServerListItem | string) => {
|
||||||
...(token && { 'x-nd-authorization': `Bearer ${token}` }),
|
...(token && { 'x-nd-authorization': `Bearer ${token}` }),
|
||||||
},
|
},
|
||||||
method: method as Method,
|
method: method as Method,
|
||||||
|
signal,
|
||||||
url: `${baseUrl}/${path}`,
|
url: `${baseUrl}/${path}`,
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import z from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
const sortOrderValues = ['ASC', 'DESC'] as const;
|
const sortOrderValues = ['ASC', 'DESC'] as const;
|
||||||
|
|
||||||
|
@ -37,6 +37,14 @@ const user = z.object({
|
||||||
|
|
||||||
const userList = z.array(user);
|
const userList = z.array(user);
|
||||||
|
|
||||||
|
const ndUserListSort = {
|
||||||
|
NAME: 'name',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const userListParameters = paginationParameters.extend({
|
||||||
|
_sort: z.nativeEnum(ndUserListSort).optional(),
|
||||||
|
});
|
||||||
|
|
||||||
const genre = z.object({
|
const genre = z.object({
|
||||||
id: z.string(),
|
id: z.string(),
|
||||||
name: z.string(),
|
name: z.string(),
|
||||||
|
@ -221,8 +229,8 @@ const ndSongListSort = {
|
||||||
|
|
||||||
const songListParameters = paginationParameters.extend({
|
const songListParameters = paginationParameters.extend({
|
||||||
_sort: z.nativeEnum(ndSongListSort).optional(),
|
_sort: z.nativeEnum(ndSongListSort).optional(),
|
||||||
album_id: z.string().optional(),
|
album_id: z.array(z.string()).optional(),
|
||||||
artist_id: z.string().optional(),
|
artist_id: z.array(z.string()).optional(),
|
||||||
genre_id: z.string().optional(),
|
genre_id: z.string().optional(),
|
||||||
starred: z.boolean().optional(),
|
starred: z.boolean().optional(),
|
||||||
});
|
});
|
||||||
|
@ -238,7 +246,7 @@ const playlist = z.object({
|
||||||
ownerName: z.string(),
|
ownerName: z.string(),
|
||||||
path: z.string(),
|
path: z.string(),
|
||||||
public: z.boolean(),
|
public: z.boolean(),
|
||||||
rules: z.string(),
|
rules: z.record(z.string(), z.any()),
|
||||||
size: z.number(),
|
size: z.number(),
|
||||||
songCount: z.number(),
|
songCount: z.number(),
|
||||||
sync: z.boolean(),
|
sync: z.boolean(),
|
||||||
|
@ -247,11 +255,27 @@ const playlist = z.object({
|
||||||
|
|
||||||
const playlistList = z.array(playlist);
|
const playlistList = z.array(playlist);
|
||||||
|
|
||||||
const playlistSong = playlist.extend({
|
const ndPlaylistListSort = {
|
||||||
|
DURATION: 'duration',
|
||||||
|
NAME: 'name',
|
||||||
|
OWNER: 'ownerName',
|
||||||
|
PUBLIC: 'public',
|
||||||
|
SONG_COUNT: 'songCount',
|
||||||
|
UPDATED_AT: 'updatedAt',
|
||||||
|
} as const;
|
||||||
|
|
||||||
|
const playlistListParameters = paginationParameters.extend({
|
||||||
|
_sort: z.nativeEnum(ndPlaylistListSort).optional(),
|
||||||
|
owner_id: z.string().optional(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const playlistSong = song.extend({
|
||||||
mediaFileId: z.string(),
|
mediaFileId: z.string(),
|
||||||
playlistId: z.string(),
|
playlistId: z.string(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const playlistSongList = z.array(playlistSong);
|
||||||
|
|
||||||
const createPlaylist = playlist.pick({
|
const createPlaylist = playlist.pick({
|
||||||
id: true,
|
id: true,
|
||||||
});
|
});
|
||||||
|
@ -287,15 +311,24 @@ const removeFromPlaylistParameters = z.object({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const ndType = {
|
export const ndType = {
|
||||||
|
_enum: {
|
||||||
|
albumArtistList: ndAlbumArtistListSort,
|
||||||
|
albumList: ndAlbumListSort,
|
||||||
|
playlistList: ndPlaylistListSort,
|
||||||
|
songList: ndSongListSort,
|
||||||
|
userList: ndUserListSort,
|
||||||
|
},
|
||||||
_parameters: {
|
_parameters: {
|
||||||
addToPlaylist: addToPlaylistParameters,
|
addToPlaylist: addToPlaylistParameters,
|
||||||
albumArtistList: albumArtistListParameters,
|
albumArtistList: albumArtistListParameters,
|
||||||
albumList: albumListParameters,
|
albumList: albumListParameters,
|
||||||
authenticate: authenticateParameters,
|
authenticate: authenticateParameters,
|
||||||
createPlaylist: createPlaylistParameters,
|
createPlaylist: createPlaylistParameters,
|
||||||
|
playlistList: playlistListParameters,
|
||||||
removeFromPlaylist: removeFromPlaylistParameters,
|
removeFromPlaylist: removeFromPlaylistParameters,
|
||||||
songList: songListParameters,
|
songList: songListParameters,
|
||||||
updatePlaylist: updatePlaylistParameters,
|
updatePlaylist: updatePlaylistParameters,
|
||||||
|
userList: userListParameters,
|
||||||
},
|
},
|
||||||
_response: {
|
_response: {
|
||||||
addToPlaylist,
|
addToPlaylist,
|
||||||
|
@ -311,6 +344,7 @@ export const ndType = {
|
||||||
playlist,
|
playlist,
|
||||||
playlistList,
|
playlistList,
|
||||||
playlistSong,
|
playlistSong,
|
||||||
|
playlistSongList,
|
||||||
removeFromPlaylist,
|
removeFromPlaylist,
|
||||||
song,
|
song,
|
||||||
songList,
|
songList,
|
||||||
|
|
Reference in a new issue