memorium/routes/api/resources.ts

22 lines
632 B
TypeScript
Raw Normal View History

2023-08-05 21:52:43 +02:00
import { Handlers } from "$fresh/server.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
2023-08-05 21:52:43 +02:00
import { getTypeSenseClient } from "@lib/typesense.ts";
import { json } from "@lib/helpers.ts";
2023-08-10 16:59:18 +02:00
import { parseResourceUrl, searchResource } from "@lib/search.ts";
2023-08-05 21:52:43 +02:00
export const handler: Handlers = {
async GET(req, ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
2023-08-10 16:59:18 +02:00
const searchParams = parseResourceUrl(req.url);
2023-08-08 21:50:23 +02:00
2023-08-05 21:52:43 +02:00
// Perform the Typesense search
2023-08-10 16:59:18 +02:00
const searchResults = await searchResource(searchParams);
2023-08-05 21:52:43 +02:00
2023-08-06 17:47:26 +02:00
return json(searchResults);
2023-08-05 21:52:43 +02:00
},
};