Files
memorium/routes/api/tmdb/query.ts
2026-01-10 13:03:29 +01:00

29 lines
705 B
TypeScript

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));
},
});