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 }); }