fix: make search usable again

This commit is contained in:
Max Richter
2025-11-05 00:42:53 +01:00
parent 7664abe089
commit 581f1c1926
9 changed files with 120 additions and 62 deletions

View File

@@ -1,7 +1,7 @@
import { Handlers } from "$fresh/server.ts";
import { json } from "@lib/helpers.ts";
import { AccessDeniedError } from "@lib/errors.ts";
import { searchResource } from "@lib/search.ts";
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
import { parseResourceUrl, searchResource } from "@lib/search.ts";
export const handler: Handlers = {
async GET(req, ctx) {
@@ -10,18 +10,13 @@ export const handler: Handlers = {
throw new AccessDeniedError();
}
const url = new URL(req.url);
const s = parseResourceUrl(req.url);
if (!s) {
throw new BadRequestError();
}
const types = url.searchParams.get("types")?.split(",");
const tags = url.searchParams?.get("tags")?.split(",");
const authors = url.searchParams?.get("authors")?.split(",");
const resources = await searchResource({
q: url.searchParams.get("q") || "",
types,
tags,
authors,
});
console.log(s);
const resources = await searchResource(s);
return json(resources);
},