sunnymh/app/api/upload/route.ts
yiekheng 4f5d74e1c8 Squashed 'manga-site/' content from commit f2ef775
git-subtree-dir: manga-site
git-subtree-split: f2ef775f7095dc2b107b576cd4053593e89dd887
2026-04-12 18:47:51 +08:00

20 lines
540 B
TypeScript

import { NextRequest } from "next/server";
import { getPresignedUploadUrl, getPublicUrl } from "@/lib/r2";
export async function POST(request: NextRequest) {
const body = await request.json();
const { key } = body;
if (!key || typeof key !== "string") {
return Response.json(
{ error: "Missing required field: key (e.g. manga/1/1/1.webp)" },
{ status: 400 }
);
}
const uploadUrl = await getPresignedUploadUrl(key);
const publicUrl = getPublicUrl(key);
return Response.json({ uploadUrl, publicUrl });
}