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,12 +1,21 @@
import { gunzipSync } from "bun";
import { unpack } from "msgpackr";
import { apiContext } from "service-srv"; import { apiContext } from "service-srv";
import { execQuery } from "utils/query"; import { execQuery } from "utils/query";
const g = global as any; const g = global as any;
export const _ = { export const _ = {
url: "/_dbs/*", url: "/_dbs/*",
raw: true,
async api() { async api() {
const { req, res } = apiContext(this); const { req, res } = apiContext(this);
if (typeof g.db !== "undefined") { if (typeof g.db !== "undefined") {
const body = req.params; if (req.params._ === "check") {
return { mode: "encrypted" };
}
try {
const body = unpack(gunzipSync(await req.arrayBuffer()));
try { try {
const result = await execQuery(body, g.db); const result = await execQuery(body, g.db);
@ -16,6 +25,10 @@ export const _ = {
res.sendStatus(500); res.sendStatus(500);
res.send(e.message); res.send(e.message);
} }
} catch (e) {
res.sendStatus(500);
res.send('{status: "unauthorized"}');
}
} }
}, },
}; };