29 lines
744 B
TypeScript
Raw Normal View History

2023-08-02 18:13:31 +02:00
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
2023-08-04 22:35:25 +02:00
import { AccessDeniedError } from "@lib/errors.ts";
2025-01-05 23:14:19 +01:00
import { searchResource } from "@lib/search.ts";
2023-08-02 18:13:31 +02:00
export const handler: Handlers = {
2023-08-04 22:35:25 +02:00
async GET(req, ctx) {
const session = ctx.state.session;
if (!session) {
throw new AccessDeniedError();
}
2023-08-02 18:13:31 +02:00
const url = new URL(req.url);
2025-01-05 23:14:19 +01:00
const types = url.searchParams.get("types")?.split(",");
2023-08-02 18:13:31 +02:00
const tags = url.searchParams?.get("tags")?.split(",");
2025-01-05 23:14:19 +01:00
const authors = url.searchParams?.get("authors")?.split(",");
const resources = await searchResource({
q: url.searchParams.get("q") || "",
types,
tags,
authors,
});
2023-08-02 18:13:31 +02:00
return json(resources);
},
};