Fix subsonic params parser
This commit is contained in:
parent
e3665e6407
commit
87abd0c6f5
1 changed files with 17 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
import { initClient, initContract } from '@ts-rest/core';
|
import { initClient, initContract } from '@ts-rest/core';
|
||||||
import axios, { Method, AxiosError, isAxiosError, AxiosResponse } from 'axios';
|
import axios, { Method, AxiosError, isAxiosError, AxiosResponse } from 'axios';
|
||||||
|
import omitBy from 'lodash/omitBy';
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { ssType } from '/@/renderer/api/subsonic/subsonic-types';
|
import { ssType } from '/@/renderer/api/subsonic/subsonic-types';
|
||||||
|
@ -101,6 +102,18 @@ axiosClient.interceptors.response.use(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const parsePath = (fullPath: string) => {
|
||||||
|
const [path, params] = fullPath.split('?');
|
||||||
|
|
||||||
|
const parsedParams = qs.parse(params);
|
||||||
|
const notNilParams = omitBy(parsedParams, (value) => value === 'undefined' || value === 'null');
|
||||||
|
|
||||||
|
return {
|
||||||
|
params: notNilParams,
|
||||||
|
path,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
export const ssApiClient = (args: {
|
export const ssApiClient = (args: {
|
||||||
server: ServerListItem | null;
|
server: ServerListItem | null;
|
||||||
signal?: AbortSignal;
|
signal?: AbortSignal;
|
||||||
|
@ -113,6 +126,8 @@ export const ssApiClient = (args: {
|
||||||
let baseUrl: string | undefined;
|
let baseUrl: string | undefined;
|
||||||
const authParams: Record<string, any> = {};
|
const authParams: Record<string, any> = {};
|
||||||
|
|
||||||
|
const { params, path: api } = parsePath(path);
|
||||||
|
|
||||||
if (server) {
|
if (server) {
|
||||||
baseUrl = `${server.url}/rest`;
|
baseUrl = `${server.url}/rest`;
|
||||||
const token = server.credential;
|
const token = server.credential;
|
||||||
|
@ -139,9 +154,10 @@ export const ssApiClient = (args: {
|
||||||
f: 'json',
|
f: 'json',
|
||||||
v: '1.13.0',
|
v: '1.13.0',
|
||||||
...authParams,
|
...authParams,
|
||||||
|
...params,
|
||||||
},
|
},
|
||||||
signal,
|
signal,
|
||||||
url: `${baseUrl}/${path}`,
|
url: `${baseUrl}/${api}`,
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
Reference in a new issue