Skip to content

Commit

Permalink
[*] Fix data response
Browse files Browse the repository at this point in the history
  • Loading branch information
Muska-Ami committed Sep 6, 2024
1 parent a106570 commit 7959f65
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 39 deletions.
9 changes: 7 additions & 2 deletions src/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ const base = {
api_v1_url: 'https://api.locyanfrp.cn',
api_v2_url: 'https://api-v2.locyanfrp.cn/api/v2',
buildResponse: (res: any, useDataPath: boolean = true) => {
const message = res.data?.data?.message ?? res.data?.data?.msg ?? res.data?.message ?? res.data?.msg ?? '未指定或请求失败'
const data = useDataPath ? res.data?.data : res.data ?? {}
const message =
res.data?.data?.message ??
res.data?.data?.msg ??
res.data?.message ??
res.data?.msg ??
'未指定或请求失败'
const data = (useDataPath ? res.data?.data : res.data) ?? {}
return {
status: res.status as number,
message: message,
Expand Down
54 changes: 21 additions & 33 deletions src/utils/logger.ts
Original file line number Diff line number Diff line change
@@ -1,40 +1,28 @@
const style = {
info: {
levelColor: 'color: #00cc00;'
},
warn: {
levelColor: 'color: #ff9933;'
},
error: {
levelColor: 'color: red;'
},
reset: 'color: none; background: none;'
info: {
levelColor: 'color: #00cc00;'
},
warn: {
levelColor: 'color: #ff9933;'
},
error: {
levelColor: 'color: red;'
},
reset: 'color: none; background: none;'
}

const logger = {
info: (m: any) => {
console.log(
`[%cINFO%c] ${m}`,
style.info.levelColor,
style.reset
)
},
warn: (m: any, clevel = true) => {
const fn = (clevel) ? console.warn : console.log
fn(
`[%cWARN%c] ${m}`,
style.warn.levelColor,
style.reset
)
},
error: (m: any, clevel = true) => {
const fn = (clevel) ? console.error : console.log
fn(
`[%cERROR%c] ${m}`,
style.error.levelColor,
style.reset
)
},
info: (m: any) => {
console.log(`[%cINFO%c] ${m}`, style.info.levelColor, style.reset)
},
warn: (m: any, clevel = true) => {
const fn = clevel ? console.warn : console.log
fn(`[%cWARN%c] ${m}`, style.warn.levelColor, style.reset)
},
error: (m: any, clevel = true) => {
const fn = clevel ? console.error : console.log
fn(`[%cERROR%c] ${m}`, style.error.levelColor, style.reset)
}
}

export default logger
5 changes: 1 addition & 4 deletions src/utils/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ const instance = axios.create({
timeout: 80000
})

const tokenDomains = [
'api.locyanfrp.cn',
'api-v2.locyanfrp.cn'
]
const tokenDomains = ['api.locyanfrp.cn', 'api-v2.locyanfrp.cn']

// post请求的时候,我们需要加上一个请求头,所以可以在这里进行一个默认的设置,即设置post的请求头为
axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded;charset=UTF-8'
Expand Down

0 comments on commit 7959f65

Please sign in to comment.