24 lines
585 B
TypeScript
24 lines
585 B
TypeScript
import { Handlers } from "$fresh/server.ts";
|
|
import { json } from "@lib/helpers.ts";
|
|
import { AccessDeniedError, BadRequestError } from "@lib/errors.ts";
|
|
import { parseResourceUrl, searchResource } from "@lib/search.ts";
|
|
|
|
export const handler: Handlers = {
|
|
async GET(req, ctx) {
|
|
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);
|
|
},
|
|
};
|