18 lines
569 B
TypeScript
18 lines
569 B
TypeScript
import { Router } from "@oak/oak";
|
|
import { fetchRichContent, isValidHttpUrl } from "../services/rich-content-service.ts";
|
|
|
|
const previewRouter = new Router();
|
|
|
|
previewRouter.get("/api/preview", async (ctx) => {
|
|
const url = ctx.request.url.searchParams.get("url") ?? "";
|
|
if (!isValidHttpUrl(url)) {
|
|
ctx.response.status = 400;
|
|
ctx.response.body = { success: false, error: { message: "Invalid URL" } };
|
|
return;
|
|
}
|
|
const data = await fetchRichContent(url);
|
|
ctx.response.body = { success: true, data: data ?? null };
|
|
});
|
|
|
|
export default previewRouter;
|