Adds /api/health, ntfy notify on config save, /admin/analytics charts, and deploy smoke for miniprogram config/API. Co-authored-by: Cursor <cursoragent@cursor.com>
42 lines
1.4 KiB
TypeScript
42 lines
1.4 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();
|
|
const merged = mergeRemoteConfig({ ...current, ...body.config });
|
|
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 });
|
|
}
|