Pay-then-profile join desk with live card, S3 upload fallback, hydration-safe drafts; document on test9 README. Co-authored-by: Cursor <cursoragent@cursor.com>
47 lines
1.5 KiB
Python
47 lines
1.5 KiB
Python
"""运营:ntfy 状态 / 试推 — admin.nomadro.com 与 .cn 共用。"""
|
||
from __future__ import annotations
|
||
|
||
from fastapi import APIRouter, Depends
|
||
from pydantic import BaseModel, Field
|
||
|
||
from ebook_svc.config import settings
|
||
from ebook_svc.core.security import require_admin
|
||
from ebook_svc.services import ntfy as ntfy_svc
|
||
|
||
router = APIRouter(prefix="/api/admin/ops", tags=["ops-admin"])
|
||
|
||
|
||
class NtfyTestBody(BaseModel):
|
||
title: str = Field(default="[WebAdmin] 试推", max_length=80)
|
||
message: str = Field(default="admin.nomadro.com 通知通路正常", max_length=500)
|
||
priority: int = Field(default=3, ge=1, le=5)
|
||
tags: str | None = Field(default="white_check_mark,globe_with_meridians")
|
||
|
||
|
||
@router.get("/ntfy")
|
||
async def ntfy_status(_: str = Depends(require_admin)) -> dict:
|
||
base = (settings.ntfy_base_url or "").rstrip("/")
|
||
topic = (settings.ntfy_topic or "").strip().strip("/")
|
||
return {
|
||
"enabled": bool(settings.ntfy_enabled),
|
||
"baseUrl": base,
|
||
"topic": topic,
|
||
"hasToken": bool((settings.ntfy_token or "").strip()),
|
||
"publicHint": "https://ntfy.nomadro.cn/" + topic if topic else "",
|
||
}
|
||
|
||
|
||
@router.post("/ntfy/test")
|
||
async def ntfy_test(body: NtfyTestBody, _: str = Depends(require_admin)) -> dict:
|
||
ok = await ntfy_svc.notify(
|
||
body.message,
|
||
title=body.title[:80],
|
||
tags=body.tags,
|
||
priority=body.priority,
|
||
)
|
||
return {
|
||
"ok": ok,
|
||
"enabled": bool(settings.ntfy_enabled),
|
||
"topic": (settings.ntfy_topic or "").strip(),
|
||
}
|