git-subtree-dir: manga-site git-subtree-split: f2ef775f7095dc2b107b576cd4053593e89dd887
20 lines
540 B
TypeScript
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 });
|
|
}
|