2024-08-27 13:15:36 +02:00
|
|
|
import { NextResponse } from "next/server";
|
|
|
|
import clientPromise from "@/lib/db";
|
|
|
|
import { ObjectId } from "mongodb";
|
|
|
|
|
|
|
|
export const dynamic = "force-dynamic";
|
|
|
|
|
|
|
|
export async function PUT(
|
2024-09-07 09:12:48 +02:00
|
|
|
request: Request,
|
|
|
|
{ params }: { params: { id: string } }
|
2024-08-27 13:15:36 +02:00
|
|
|
) {
|
2024-09-07 09:12:48 +02:00
|
|
|
const { id } = params;
|
|
|
|
const body = await request.json();
|
|
|
|
const { fileName, version, downloadLink, fileSize } = body;
|
2024-08-27 13:15:36 +02:00
|
|
|
|
2024-09-07 09:12:48 +02:00
|
|
|
try {
|
|
|
|
const client = await clientPromise;
|
|
|
|
const db = client.db("downloadsDatabase");
|
2024-08-27 13:15:36 +02:00
|
|
|
|
2024-09-07 09:12:48 +02:00
|
|
|
const result = await db.collection("mods").updateOne(
|
|
|
|
{ _id: new ObjectId(id) },
|
|
|
|
{
|
|
|
|
$set: {
|
|
|
|
fileName,
|
|
|
|
version,
|
|
|
|
downloadLink,
|
|
|
|
fileSize
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2024-08-27 13:15:36 +02:00
|
|
|
|
2024-09-07 09:12:48 +02:00
|
|
|
if (result.modifiedCount > 0) {
|
|
|
|
return NextResponse.json({ success: true });
|
|
|
|
} else {
|
|
|
|
return NextResponse.json({
|
|
|
|
success: false,
|
|
|
|
message: "No document updated"
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.error("Update failed", error);
|
|
|
|
return NextResponse.json({
|
|
|
|
success: false,
|
|
|
|
message: "Failed to update mod"
|
|
|
|
});
|
|
|
|
}
|
2024-08-27 13:15:36 +02:00
|
|
|
}
|