feat: add localization and site settings
This commit is contained in:
@@ -1,17 +1,26 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/db";
|
||||
import { auth } from "@/lib/auth";
|
||||
import { getApiLang, pickText } from "@/lib/api-locale";
|
||||
import { getApiWowVersion } from "@/lib/wow-versions";
|
||||
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
request: NextRequest,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
const { id } = await params;
|
||||
const lang = getApiLang(request);
|
||||
const wowVersion = getApiWowVersion(request);
|
||||
const { searchParams } = new URL(request.url);
|
||||
const wowAll = searchParams.get("wow") === "all";
|
||||
|
||||
const software = await prisma.software.findFirst({
|
||||
where: { OR: [{ id }, { slug: id }] },
|
||||
include: {
|
||||
versions: { orderBy: { versionCode: "desc" } },
|
||||
versions: {
|
||||
...(wowAll ? {} : { where: { wowVersion } }),
|
||||
orderBy: { versionCode: "desc" },
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -19,7 +28,23 @@ export async function GET(
|
||||
return NextResponse.json({ error: "Not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(software);
|
||||
return NextResponse.json({
|
||||
...software,
|
||||
name: pickText(software.name, software.nameEn, lang),
|
||||
description: pickText(software.description, software.descriptionEn, lang),
|
||||
nameZh: software.name,
|
||||
descriptionZh: software.description,
|
||||
nameEn: software.nameEn,
|
||||
descriptionEn: software.descriptionEn,
|
||||
versions: software.versions.map((v) => ({
|
||||
...v,
|
||||
changelog: pickText(v.changelog, v.changelogEn, lang),
|
||||
changelogZh: v.changelog,
|
||||
changelogEn: v.changelogEn,
|
||||
})),
|
||||
lang,
|
||||
wowVersion: wowAll ? "all" : wowVersion,
|
||||
});
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
@@ -38,8 +63,12 @@ export async function PUT(
|
||||
where: { id },
|
||||
data: {
|
||||
...(body.name !== undefined && { name: body.name }),
|
||||
...(body.nameEn !== undefined && { nameEn: body.nameEn }),
|
||||
...(body.slug !== undefined && { slug: body.slug }),
|
||||
...(body.description !== undefined && { description: body.description }),
|
||||
...(body.descriptionEn !== undefined && {
|
||||
descriptionEn: body.descriptionEn,
|
||||
}),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user