Ship admin nav editor + navContent remote-config, custom nav bars for memo/store, and weapp icon copy/webp path so nav icons render in DevTools. Co-authored-by: Cursor <cursoragent@cursor.com>
58 lines
2.0 KiB
TypeScript
58 lines
2.0 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { requireAdminSession } from "~/lib/admin-auth";
|
|
import {
|
|
readRemoteConfigFile,
|
|
writeRemoteConfigFile,
|
|
} from "~/lib/remote-config-store";
|
|
import {
|
|
mergeRemoteConfig,
|
|
type NomadroRemoteConfig,
|
|
} from "~/lib/remote-config";
|
|
import { publishNtfy } from "~/lib/ntfy";
|
|
|
|
export async function GET() {
|
|
if (!(await requireAdminSession())) {
|
|
return NextResponse.json({ ok: false, error: "unauthorized" }, { status: 401 });
|
|
}
|
|
const config = await readRemoteConfigFile();
|
|
return NextResponse.json({ ok: true, config });
|
|
}
|
|
|
|
export async function PUT(request: Request) {
|
|
if (!(await requireAdminSession())) {
|
|
return NextResponse.json({ ok: false, error: "unauthorized" }, { status: 401 });
|
|
}
|
|
const body = (await request.json().catch(() => ({}))) as {
|
|
config?: Partial<NomadroRemoteConfig>;
|
|
};
|
|
if (!body.config) {
|
|
return NextResponse.json({ ok: false, error: "missing config" }, { status: 400 });
|
|
}
|
|
const current = await readRemoteConfigFile();
|
|
// 浅合并顶层后走 mergeRemoteConfig / write 自检;未提交的 platforms.tt 保留现网
|
|
const merged = mergeRemoteConfig({
|
|
...current,
|
|
...body.config,
|
|
modules: { ...current.modules, ...(body.config.modules || {}) },
|
|
flags: { ...current.flags, ...(body.config.flags || {}) },
|
|
copy: { ...current.copy, ...(body.config.copy || {}) },
|
|
navContent: body.config.navContent ?? current.navContent,
|
|
platforms: {
|
|
tt: body.config.platforms?.tt ?? current.platforms?.tt,
|
|
},
|
|
});
|
|
try {
|
|
const saved = await writeRemoteConfigFile(merged);
|
|
void publishNtfy({
|
|
title: "远程配置已更新",
|
|
message: `v${saved.version} · ${saved.updatedAt || "now"} · ${saved.copy?.homeBrand || "nomadro"}`,
|
|
tags: "gear,nomadro",
|
|
priority: "default",
|
|
});
|
|
return NextResponse.json({ ok: true, config: saved });
|
|
} catch (e) {
|
|
const msg = e instanceof Error ? e.message : "save failed";
|
|
return NextResponse.json({ ok: false, error: msg }, { status: 400 });
|
|
}
|
|
}
|