nomadro/app/api/admin/notify/route.ts
eric 9f8fec1723 Ship portal PC/H5 acceptance, VIP ScrollReader, admin analytics and ops anchors.
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>
2026-09-28 23:52:00 -05:00

44 lines
1.4 KiB
TypeScript

import { NextResponse } from "next/server";
import { requireAdminSession } from "~/lib/admin-auth";
import { ntfyConfigured, publishNtfy } from "~/lib/ntfy";
export async function GET() {
if (!(await requireAdminSession())) {
return NextResponse.json({ ok: false, error: "unauthorized" }, { status: 401 });
}
return NextResponse.json({
ok: true,
configured: ntfyConfigured(),
baseUrl: process.env.NTFY_BASE_URL || "https://ntfy.nomadro.cn",
topic: process.env.NTFY_TOPIC || "nomadro",
hasToken: Boolean((process.env.NTFY_TOKEN || "").trim()),
});
}
/** Instant ntfy push from admin panel. */
export async function POST(request: Request) {
if (!(await requireAdminSession())) {
return NextResponse.json({ ok: false, error: "unauthorized" }, { status: 401 });
}
const body = (await request.json().catch(() => ({}))) as {
title?: string;
message?: string;
priority?: string | number;
tags?: string;
topic?: string;
};
const title = (body.title || "Nomadro Admin").trim();
const message = (body.message || "手动测试推送").trim();
if (!title || !message) {
return NextResponse.json({ ok: false, error: "missing title/message" }, { status: 400 });
}
const result = await publishNtfy({
title,
message,
priority: body.priority as never,
tags: body.tags || "loudspeaker,nomadro",
topic: body.topic,
});
return NextResponse.json(result, { status: result.ok ? 200 : 502 });
}