From edf54f4fbc8ba8452952240d040b414f79efd75f Mon Sep 17 00:00:00 2001 From: Patrick Alvin Alcala Date: Tue, 3 Mar 2026 16:39:50 +0800 Subject: [PATCH] Added voidApi --- src/utils/functions/index.ts | 1 + src/utils/functions/voidApi.ts | 36 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 src/utils/functions/voidApi.ts diff --git a/src/utils/functions/index.ts b/src/utils/functions/index.ts index a0a01fd..e2a7824 100644 --- a/src/utils/functions/index.ts +++ b/src/utils/functions/index.ts @@ -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' diff --git a/src/utils/functions/voidApi.ts b/src/utils/functions/voidApi.ts new file mode 100644 index 0000000..56b7c0d --- /dev/null +++ b/src/utils/functions/voidApi.ts @@ -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' + } +}