Modify navidrome responses to include header
This commit is contained in:
parent
fe043d1823
commit
438085633b
1 changed files with 27 additions and 20 deletions
|
@ -1,6 +1,7 @@
|
||||||
import { initClient, initContract } from '@ts-rest/core';
|
import { initClient, initContract } from '@ts-rest/core';
|
||||||
import axios, { Method, AxiosError, AxiosResponse, isAxiosError } from 'axios';
|
import axios, { Method, AxiosError, AxiosResponse, isAxiosError } from 'axios';
|
||||||
import { ndType } from './navidrome-types';
|
import { ndType } from './navidrome-types';
|
||||||
|
import { resultWithHeaders } from '/@/renderer/api/utils';
|
||||||
import { toast } from '/@/renderer/components';
|
import { toast } from '/@/renderer/components';
|
||||||
import { useAuthStore } from '/@/renderer/store';
|
import { useAuthStore } from '/@/renderer/store';
|
||||||
|
|
||||||
|
@ -12,7 +13,7 @@ export const contract = c.router({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: 'playlist/:id/tracks',
|
path: 'playlist/:id/tracks',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.addToPlaylist,
|
200: resultWithHeaders(ndType._response.addToPlaylist),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
authenticate: {
|
authenticate: {
|
||||||
|
@ -20,7 +21,7 @@ export const contract = c.router({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: 'auth/login',
|
path: 'auth/login',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.authenticate,
|
200: resultWithHeaders(ndType._response.authenticate),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
createPlaylist: {
|
createPlaylist: {
|
||||||
|
@ -28,7 +29,7 @@ export const contract = c.router({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
path: 'playlist',
|
path: 'playlist',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.createPlaylist,
|
200: resultWithHeaders(ndType._response.createPlaylist),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
deletePlaylist: {
|
deletePlaylist: {
|
||||||
|
@ -36,79 +37,79 @@ export const contract = c.router({
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
path: 'playlist/:id',
|
path: 'playlist/:id',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.deletePlaylist,
|
200: resultWithHeaders(ndType._response.deletePlaylist),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getAlbumArtistDetail: {
|
getAlbumArtistDetail: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'albumArtist/:id',
|
path: 'albumArtist/:id',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.albumArtist,
|
200: resultWithHeaders(ndType._response.albumArtist),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getAlbumArtistList: {
|
getAlbumArtistList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'albumArtist',
|
path: 'albumArtist',
|
||||||
pathParams: ndType._parameters.albumArtistList,
|
query: ndType._parameters.albumArtistList,
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.albumArtistList,
|
200: resultWithHeaders(ndType._response.albumArtistList),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getAlbumDetail: {
|
getAlbumDetail: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'album/:id',
|
path: 'album/:id',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.album,
|
200: resultWithHeaders(ndType._response.album),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getAlbumList: {
|
getAlbumList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'album',
|
path: 'album',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.albumList,
|
200: resultWithHeaders(ndType._response.albumList),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getGenreList: {
|
getGenreList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'genre',
|
path: 'genre',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.genreList,
|
200: resultWithHeaders(ndType._response.genreList),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getPlaylistDetail: {
|
getPlaylistDetail: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'playlist/:id',
|
path: 'playlist/:id',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.playlist,
|
200: resultWithHeaders(ndType._response.playlist),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getPlaylistList: {
|
getPlaylistList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'playlist',
|
path: 'playlist',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.playlistList,
|
200: resultWithHeaders(ndType._response.playlistList),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getSongDetail: {
|
getSongDetail: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'song/:id',
|
path: 'song/:id',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.song,
|
200: resultWithHeaders(ndType._response.song),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getSongList: {
|
getSongList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'song',
|
path: 'song',
|
||||||
pathParams: ndType._parameters.songList,
|
query: ndType._parameters.songList,
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.songList,
|
200: resultWithHeaders(ndType._response.songList),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
getUserList: {
|
getUserList: {
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path: 'user',
|
path: 'user',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.userList,
|
200: resultWithHeaders(ndType._response.userList),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
removeFromPlaylist: {
|
removeFromPlaylist: {
|
||||||
|
@ -117,7 +118,7 @@ export const contract = c.router({
|
||||||
path: 'playlist/:id/tracks',
|
path: 'playlist/:id/tracks',
|
||||||
query: ndType._parameters.removeFromPlaylist,
|
query: ndType._parameters.removeFromPlaylist,
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.removeFromPlaylist,
|
200: resultWithHeaders(ndType._response.removeFromPlaylist),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
updatePlaylist: {
|
updatePlaylist: {
|
||||||
|
@ -125,7 +126,7 @@ export const contract = c.router({
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
path: 'playlist/:id',
|
path: 'playlist/:id',
|
||||||
responses: {
|
responses: {
|
||||||
200: ndType._response.updatePlaylist,
|
200: resultWithHeaders(ndType._response.updatePlaylist),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -175,12 +176,18 @@ export const ndApiClient = initClient(contract, {
|
||||||
method: method as Method,
|
method: method as Method,
|
||||||
url: `${baseUrl}/${path}`,
|
url: `${baseUrl}/${path}`,
|
||||||
});
|
});
|
||||||
return { body: result.data, status: result.status };
|
return {
|
||||||
|
body: { data: result.data, headers: result.headers },
|
||||||
|
status: result.status,
|
||||||
|
};
|
||||||
} catch (e: Error | AxiosError | any) {
|
} catch (e: Error | AxiosError | any) {
|
||||||
if (isAxiosError(e)) {
|
if (isAxiosError(e)) {
|
||||||
const error = e as AxiosError;
|
const error = e as AxiosError;
|
||||||
const response = error.response as AxiosResponse;
|
const response = error.response as AxiosResponse;
|
||||||
return { body: response.data, status: response.status };
|
return {
|
||||||
|
body: { data: response.data, headers: response.headers },
|
||||||
|
status: response.status,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
Reference in a new issue