From 0825b55d820a2c8aec301c4ad3139e941302a26b Mon Sep 17 00:00:00 2001 From: Rizky Date: Thu, 29 Aug 2024 10:10:49 +0700 Subject: [PATCH] fix --- pkgs/api/_dbs.ts | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/pkgs/api/_dbs.ts b/pkgs/api/_dbs.ts index 01cfb06..aae6412 100644 --- a/pkgs/api/_dbs.ts +++ b/pkgs/api/_dbs.ts @@ -1,20 +1,33 @@ +import { gunzipSync } from "bun"; +import { unpack } from "msgpackr"; import { apiContext } from "service-srv"; import { execQuery } from "utils/query"; + const g = global as any; export const _ = { url: "/_dbs/*", + raw: true, async api() { const { req, res } = apiContext(this); if (typeof g.db !== "undefined") { - const body = req.params; + if (req.params._ === "check") { + return { mode: "encrypted" }; + } try { - const result = await execQuery(body, g.db); - return result; - } catch (e: any) { - console.log("_dbs error", body, e.message); + const body = unpack(gunzipSync(await req.arrayBuffer())); + + try { + const result = await execQuery(body, g.db); + return result; + } catch (e: any) { + console.log("_dbs error", body, e.message); + res.sendStatus(500); + res.send(e.message); + } + } catch (e) { res.sendStatus(500); - res.send(e.message); + res.send('{status: "unauthorized"}'); } } },