This commit is contained in:
Patrick Alvin Alcala 2025-11-20 13:03:40 +08:00
parent 4184942584
commit afb5f3a287
66 changed files with 550 additions and 57 deletions

View file

@ -0,0 +1,35 @@
import { ofetch } from 'ofetch'
import { $backendUrl } from '../../../../configs/config.api'
import { $tokenName, $tokenExpiration } from '../../../../configs/config.security'
import dayjs from 'dayjs'
import encryptRsa from '../../scripts/functions/encryptRsa'
const URL = $backendUrl.get()
const TOKEN_NAME = $tokenName.get()
const TOKEN_EXPIRATION = $tokenExpiration.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: 3,
retryDelay: 500,
retryStatusCodes: [400, 404, 405, 500, 502],
method: 'POST',
body: body,
})
return true
} catch {
return false
}
}