import { searchMovie, searchTVShow } from "@lib/tmdb.ts"; import { AccessDeniedError, BadRequestError } from "@lib/errors.ts"; import { define } from "../../../utils.ts"; export const handler = define.handlers({ GET: async (ctx) => { const session = ctx.state.session; if (!session) { throw new AccessDeniedError(); } const u = new URL(ctx.req.url); const query = u.searchParams.get("q"); if (!query) { throw new BadRequestError(); } const type = u.searchParams.get("type") || "movies"; const res = type === "movies" ? await searchMovie(query) : await searchTVShow(query); return new Response(JSON.stringify(res.results)); }, });