svrjs-nextjs-website/app/api/upload/route.ts

27 lines
742 B
TypeScript
Raw Normal View History

2024-06-20 19:46:48 +02:00
import { NextResponse } from "next/server";
import clientPromise from "@/lib/db";
import { revalidatePath } from "next/cache";
2024-06-20 19:46:48 +02:00
// Force the API to use SSR instead of static generation
export const dynamic = "force-dynamic";
2024-06-20 19:46:48 +02:00
export async function POST(request: Request) {
const body = await request.json();
const { fileName, version, downloadLink, fileSize } = body;
const client = await clientPromise;
const db = client.db(process.env.MONGODB_DB);
2024-06-20 19:46:48 +02:00
const result = await db.collection("downloads").insertOne({
date: new Date().toISOString().split("T")[0],
fileName,
version,
downloadLink,
fileSize
2024-06-20 19:46:48 +02:00
});
revalidatePath("/downloads");
2024-06-20 19:46:48 +02:00
return NextResponse.json({ success: true, id: result.insertedId });
}