This commit is contained in:
Rizky 2024-08-29 10:10:49 +07:00
parent 1cca29d504
commit 0825b55d82
1 changed files with 19 additions and 6 deletions

View File

@ -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"}');
}
}
},