Updated
This commit is contained in:
parent
d61b8b7bd8
commit
46783c4f38
57 changed files with 4178 additions and 5992 deletions
25
frontend/@dasig/api/functions/getApi.ts
Normal file
25
frontend/@dasig/api/functions/getApi.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import { ofetch } from 'ofetch'
|
||||
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
|
||||
|
||||
const URL = $backendUrl.get()
|
||||
const RETRY = $requestRetries.get()
|
||||
const CODES = $requestRetryCodes.get()
|
||||
|
||||
export default async (api: string, value?: any, value2?: any) => {
|
||||
try {
|
||||
let fetch
|
||||
if (!value2) {
|
||||
if (!value) {
|
||||
fetch = await ofetch(URL + api, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
|
||||
} else {
|
||||
fetch = await ofetch(URL + `${api}/${value}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
|
||||
}
|
||||
} else {
|
||||
fetch = await ofetch(URL + `${api}/${value}/${value2}/fetch-data`, { parseResponse: JSON.parse, retry: RETRY, retryDelay: 500, retryStatusCodes: CODES })
|
||||
}
|
||||
const result = fetch
|
||||
return [result, null]
|
||||
} catch (error) {
|
||||
return [[], error]
|
||||
}
|
||||
}
|
||||
37
frontend/@dasig/api/functions/postApi.ts
Normal file
37
frontend/@dasig/api/functions/postApi.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import dayjs from 'dayjs'
|
||||
import { ofetch } from 'ofetch'
|
||||
import { $backendUrl, $requestRetries, $requestRetryCodes } from '../../../../configs/config.api'
|
||||
import { $tokenExpiration, $tokenName } from '../../../../configs/config.security'
|
||||
import { encryptRsa } from '../../scripts'
|
||||
|
||||
const URL = $backendUrl.get()
|
||||
const TOKEN_NAME = $tokenName.get()
|
||||
const TOKEN_EXPIRATION = $tokenExpiration.get()
|
||||
const RETRY = $requestRetries.get()
|
||||
const CODES = $requestRetryCodes.get()
|
||||
|
||||
export default async (api: string, body: Object) => {
|
||||
const today = new Date()
|
||||
const todayUnix = dayjs(today).unix()
|
||||
const expiration = todayUnix + TOKEN_EXPIRATION
|
||||
const aes = await encryptRsa(`${api.toString()}-${todayUnix.toString()}-${expiration.toString()}`)
|
||||
|
||||
const hash = `${TOKEN_NAME}=${aes}token`
|
||||
try {
|
||||
await ofetch(URL + api, {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'Dasig-Token': hash,
|
||||
},
|
||||
retry: RETRY,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: CODES,
|
||||
method: 'POST',
|
||||
body: body,
|
||||
})
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
2
frontend/@dasig/api/index.ts
Normal file
2
frontend/@dasig/api/index.ts
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
export { default as getApi } from './functions/getApi'
|
||||
export { default as postApi } from './functions/postApi'
|
||||
Loading…
Add table
Add a link
Reference in a new issue