mirror of
https://github.com/jeffvli/feishin.git
synced 2026-05-06 20:10:12 +02:00
use urlsearchparams instead of qs
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import { initClient, initContract } from '@ts-rest/core';
|
import { initClient, initContract } from '@ts-rest/core';
|
||||||
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, isAxiosError } from 'axios';
|
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse, isAxiosError } from 'axios';
|
||||||
import omitBy from 'lodash/omitBy';
|
|
||||||
import qs from 'qs';
|
import qs from 'qs';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
|
|
||||||
@@ -380,8 +379,26 @@ axiosClient.interceptors.response.use(
|
|||||||
const parsePath = (fullPath: string) => {
|
const parsePath = (fullPath: string) => {
|
||||||
const [path, params] = fullPath.split('?');
|
const [path, params] = fullPath.split('?');
|
||||||
|
|
||||||
const parsedParams = qs.parse(params, { arrayLimit: 99999, parameterLimit: 99999 });
|
const url = new URLSearchParams(params);
|
||||||
const notNilParams = omitBy(parsedParams, (value) => value === 'undefined' || value === 'null');
|
const notNilParams: Record<string, string[]> = {};
|
||||||
|
|
||||||
|
for (const [key, value] of url) {
|
||||||
|
if (value === 'undefined' || value === 'null') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
let realKey = key;
|
||||||
|
|
||||||
|
if (key.includes('[') && key.includes(']')) {
|
||||||
|
realKey = key.split('[')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (realKey in notNilParams) {
|
||||||
|
notNilParams[realKey].push(value);
|
||||||
|
} else {
|
||||||
|
notNilParams[realKey] = [value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
params: notNilParams,
|
params: notNilParams,
|
||||||
|
|||||||
Reference in New Issue
Block a user