New delete api function
This commit is contained in:
parent
45b551511a
commit
f51edc0506
1 changed files with 31 additions and 0 deletions
31
src/utils/functions/deleteApi.ts
Normal file
31
src/utils/functions/deleteApi.ts
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
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 {
|
||||
await ofetch(API + api, {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Cache-Control': 'no-cache',
|
||||
'OCBO-Token': hash,
|
||||
},
|
||||
retry: 3,
|
||||
retryDelay: 500,
|
||||
retryStatusCodes: [400, 404, 405, 500, 502],
|
||||
method: 'DELETE',
|
||||
body: body,
|
||||
})
|
||||
return true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue