Added voidApi
This commit is contained in:
parent
ab3351679a
commit
edf54f4fbc
2 changed files with 37 additions and 0 deletions
|
|
@ -12,3 +12,4 @@ export { default as saveNewPassword } from './saveNewPassword.ts'
|
|||
export { default as getDateTime } from './getDateTime.ts'
|
||||
export { default as deleteApi } from './deleteApi.ts'
|
||||
export { default as lockData } from './lockData.ts'
|
||||
export { default as voidApi } from './voidApi.ts'
|
||||
|
|
|
|||
36
src/utils/functions/voidApi.ts
Normal file
36
src/utils/functions/voidApi.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { ofetch } from 'ofetch'
|
||||
import dayjs from 'dayjs'
|
||||
import encryptRsa from './encryptRsa'
|
||||
|
||||
const API = import.meta.env.VITE_BACKEND
|
||||
|
||||
export default async (api: string, body: Object) => {
|
||||
const today = new Date()
|
||||
const todayUnix = dayjs(today).unix()
|
||||
const expiration = todayUnix + 9
|
||||
const aes = await encryptRsa(`${api.toString()}-${todayUnix.toString()}-${expiration.toString()}`)
|
||||
|
||||
const hash = `ocbo=${aes}token`
|
||||
try {
|
||||
let data
|
||||
await ofetch(API + api, {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'OCBO-Token': hash,
|
||||
},
|
||||
async onResponse({ response }) {
|
||||
data = response.ok
|
||||
},
|
||||
retry: 3,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: [400, 404, 405, 500, 502],
|
||||
method: 'DELETE',
|
||||
body: body,
|
||||
})
|
||||
|
||||
return data
|
||||
} catch {
|
||||
return 'error'
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue