官网 初版

This commit is contained in:
rucky
2026-03-18 17:13:27 +08:00
parent 879c4bdfc8
commit 241a76caeb
95 changed files with 8889 additions and 113 deletions

View File

@@ -0,0 +1,61 @@
import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { auth } from "@/lib/auth";
export async function GET(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const { id } = await params;
const software = await prisma.software.findFirst({
where: { OR: [{ id }, { slug: id }] },
include: {
versions: { orderBy: { versionCode: "desc" } },
},
});
if (!software) {
return NextResponse.json({ error: "Not found" }, { status: 404 });
}
return NextResponse.json(software);
}
export async function PUT(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const session = await auth();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { id } = await params;
const body = await request.json();
const software = await prisma.software.update({
where: { id },
data: {
...(body.name !== undefined && { name: body.name }),
...(body.slug !== undefined && { slug: body.slug }),
...(body.description !== undefined && { description: body.description }),
},
});
return NextResponse.json(software);
}
export async function DELETE(
_request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
const session = await auth();
if (!session?.user) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
}
const { id } = await params;
await prisma.software.delete({ where: { id } });
return NextResponse.json({ success: true });
}