🐛 Fix payload case issue

This commit is contained in:
LittleSheep 2025-01-11 15:36:17 +08:00
parent bf43234eae
commit 7e0dff9f0f
5 changed files with 28 additions and 15 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -38,7 +38,7 @@
"remark-parse": "^11.0.0",
"remark-rehype": "^11.1.1",
"sitemap": "^8.0.0",
"solar-js-sdk": "^0.1.1",
"solar-js-sdk": "^0.1.2",
"unified": "^11.0.5",
"zustand": "^5.0.3"
},

View File

@ -8,7 +8,7 @@
"name": "LittleSheep",
"email": "littlesheep.code@hotmail.com"
},
"version": "0.1.1",
"version": "0.1.2",
"tsup": {
"entry": [
"src/index.ts"

View File

@ -15,18 +15,18 @@ function toCamelCase(obj: any): any {
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
// }
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'
@ -43,6 +43,19 @@ export const sni: AxiosInstance = (() => {
},
(error) => error,
)
/// Case convertor
inst.interceptors.request.use(
(config) => {
if (config.data) {
config.data = toSnakeCase(config.data)
}
return config
},
(error) => Promise.reject(error),
)
inst.interceptors.response.use(
(response) => {
if (response.data) {

View File

@ -12,7 +12,7 @@ export const getServerSideProps: GetServerSideProps = (async (context) => {
return getConsoleStaticProps({
props: {
title: `Edit Release "${data.name}"`,
title: `Edit Release v${data.version}`,
release: data,
},
})