🐛 Switch bundler and bug fixes
This commit is contained in:
parent
c1140b4e2f
commit
5d6a018c63
Binary file not shown.
@ -25,7 +25,6 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^1.7.9",
|
"axios": "^1.7.9",
|
||||||
"axios-case-converter": "^1.1.1",
|
|
||||||
"universal-cookie": "^7.2.2",
|
"universal-cookie": "^7.2.2",
|
||||||
"zustand": "^5.0.3"
|
"zustand": "^5.0.3"
|
||||||
}
|
}
|
||||||
|
@ -1,8 +1,33 @@
|
|||||||
import axios, { type AxiosInstance } from 'axios'
|
import axios, { type AxiosInstance } from 'axios'
|
||||||
import applyCaseMiddleware from 'axios-case-converter'
|
|
||||||
import Cookies from 'universal-cookie'
|
import Cookies from 'universal-cookie'
|
||||||
import { setTokenCookies } from './auth'
|
import { setTokenCookies } from './auth'
|
||||||
|
|
||||||
|
function toCamelCase(obj: any): any {
|
||||||
|
if (Array.isArray(obj)) {
|
||||||
|
return obj.map(toCamelCase)
|
||||||
|
} else if (obj && typeof obj === 'object') {
|
||||||
|
return Object.keys(obj).reduce((result: any, key) => {
|
||||||
|
const camelKey = key.replace(/_([a-z])/g, (_, char) => char.toUpperCase())
|
||||||
|
result[camelKey] = toCamelCase(obj[key])
|
||||||
|
return result
|
||||||
|
}, {})
|
||||||
|
}
|
||||||
|
return obj
|
||||||
|
}
|
||||||
|
|
||||||
|
// function toSnakeCase(obj: any): any {
|
||||||
|
// if (Array.isArray(obj)) {
|
||||||
|
// return obj.map(toSnakeCase)
|
||||||
|
// } else if (obj && typeof obj === 'object') {
|
||||||
|
// return Object.keys(obj).reduce((result: any, key) => {
|
||||||
|
// const snakeKey = key.replace(/[A-Z]/g, (char) => `_${char.toLowerCase()}`)
|
||||||
|
// result[snakeKey] = toSnakeCase(obj[key])
|
||||||
|
// return result
|
||||||
|
// }, {})
|
||||||
|
// }
|
||||||
|
// return obj
|
||||||
|
// }
|
||||||
|
|
||||||
const baseURL = 'https://api.sn.solsynth.dev'
|
const baseURL = 'https://api.sn.solsynth.dev'
|
||||||
|
|
||||||
export const sni: AxiosInstance = (() => {
|
export const sni: AxiosInstance = (() => {
|
||||||
@ -18,11 +43,21 @@ export const sni: AxiosInstance = (() => {
|
|||||||
},
|
},
|
||||||
(error) => error,
|
(error) => error,
|
||||||
)
|
)
|
||||||
|
inst.interceptors.response.use(
|
||||||
|
(response) => {
|
||||||
|
if (response.data) {
|
||||||
|
response.data = toCamelCase(response.data)
|
||||||
|
}
|
||||||
|
return response
|
||||||
|
},
|
||||||
|
(error) => {
|
||||||
|
if (error.response && error.response.data) {
|
||||||
|
error.response.data = toCamelCase(error.response.data)
|
||||||
|
}
|
||||||
|
return Promise.reject(error)
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
applyCaseMiddleware(inst, {
|
|
||||||
ignoreParams: true,
|
|
||||||
ignoreHeaders: true,
|
|
||||||
})
|
|
||||||
return inst
|
return inst
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user