Files
memorium/routes/api/query/index.ts
2026-01-10 13:03:29 +01:00

25 lines
611 B
TypeScript

import { json } from "@lib/helpers.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
import { define } from "../../../utils.ts";
export const handler = define.handlers({
async GET(ctx) {
const req = ctx.req;
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
const s = parseResourceUrl(req.url);
if (!s) {
throw new BadRequestError();
}
console.log(s);
const resources = await searchResource(s);
return json(resources);
},
});