feat: add localization and site settings

This commit is contained in:
rucky
2026-05-12 09:58:25 +08:00
parent 9dc6c0dcce
commit fa7aedb8e7
67 changed files with 5221 additions and 888 deletions

View File

@@ -2,18 +2,24 @@ import { NextRequest, NextResponse } from "next/server";
import { prisma } from "@/lib/db";
import { readFile, stat } from "fs/promises";
import path from "path";
import { getApiLang, pickText } from "@/lib/api-locale";
import { getDownloadWowVersion } from "@/lib/wow-versions";
const LAUNCHER_SLUG = "nanami-launcher";
export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const infoOnly = searchParams.get("info") === "1";
const lang = getApiLang(request);
// Download endpoint: only the URL determines what gets downloaded.
// Cookies (wow / locale) do not influence the binary.
const wowVersion = getDownloadWowVersion(request);
const software = await prisma.software.findUnique({
where: { slug: LAUNCHER_SLUG },
include: {
versions: {
where: { isLatest: true },
where: { isLatest: true, wowVersion },
take: 1,
},
},
@@ -21,10 +27,10 @@ export async function GET(request: NextRequest) {
if (!software || software.versions.length === 0) {
if (infoOnly) {
return NextResponse.json({ available: false });
return NextResponse.json({ available: false, wowVersion });
}
return NextResponse.json(
{ error: "暂无可下载版本" },
{ error: `No release available for WoW ${wowVersion}` },
{ status: 404 }
);
}
@@ -49,11 +55,15 @@ export async function GET(request: NextRequest) {
available: true,
version: latest.version,
versionCode: latest.versionCode,
changelog: latest.changelog,
changelog: pickText(latest.changelog, latest.changelogEn, lang),
changelogZh: latest.changelog,
changelogEn: latest.changelogEn,
fileSize: latest.fileSize,
createdAt: latest.createdAt,
downloadUrl,
downloadType: latest.downloadType,
wowVersion: latest.wowVersion,
lang,
});
}
@@ -79,7 +89,7 @@ export async function GET(request: NextRequest) {
const fileBuffer = await readFile(filePath);
const ext = path.extname(latest.filePath);
const fileName = `nanami-launcher-v${latest.version}${ext}`;
const fileName = `nanami-launcher-wow${latest.wowVersion}-v${latest.version}${ext}`;
return new NextResponse(fileBuffer, {
headers: {