This commit is contained in:
Patrick Alvin Alcala 2025-11-26 10:56:07 +08:00
parent d61b8b7bd8
commit 46783c4f38
57 changed files with 4178 additions and 5992 deletions

View 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]
}
}

View 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
}
}

View file

@ -0,0 +1,2 @@
export { default as getApi } from './functions/getApi'
export { default as postApi } from './functions/postApi'