fix(ops): keep webhook notify untouched; normalize Umami script
Ops/ntfy stays isolated from existing live/TikTok webhook paths. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
acbf167ebe
commit
d57a0e2acb
@ -8,81 +8,33 @@ import httpx
|
|||||||
from . import db
|
from . import db
|
||||||
|
|
||||||
|
|
||||||
def _event_allowed(event: str, cfg: dict[str, Any]) -> bool:
|
|
||||||
if event == "ops":
|
|
||||||
return True
|
|
||||||
if event == "live" and not cfg.get("notify_on_live", True):
|
|
||||||
return False
|
|
||||||
if event == "offline" and not cfg.get("notify_on_offline", False):
|
|
||||||
return False
|
|
||||||
if event == "risk" and not cfg.get("notify_on_risk", True):
|
|
||||||
return False
|
|
||||||
if event == "shorts_fail" and not cfg.get("notify_on_shorts_fail", True):
|
|
||||||
return False
|
|
||||||
if event == "shorts_ok" and not cfg.get("notify_on_shorts_ok", False):
|
|
||||||
return False
|
|
||||||
if event == "shorts_quota" and not cfg.get("notify_on_shorts_quota", True):
|
|
||||||
return False
|
|
||||||
if event == "tiktok_fail" and not cfg.get("notify_on_tiktok_fail", True):
|
|
||||||
return False
|
|
||||||
if event == "tiktok_ok" and not cfg.get("notify_on_tiktok_ok", False):
|
|
||||||
return False
|
|
||||||
if event == "tiktok_limit" and not cfg.get("notify_on_tiktok_limit", True):
|
|
||||||
return False
|
|
||||||
if event == "watch_remind" and not cfg.get("notify_on_watch_remind", True):
|
|
||||||
return False
|
|
||||||
return True
|
|
||||||
|
|
||||||
|
|
||||||
async def send_ntfy_best_effort(event: str, payload: dict[str, Any]) -> None:
|
|
||||||
"""Mirror events to self-hosted ntfy when /etc/nomadro/ntfy.env is present."""
|
|
||||||
try:
|
|
||||||
from . import ops_panel
|
|
||||||
except Exception:
|
|
||||||
return
|
|
||||||
|
|
||||||
title_map = {
|
|
||||||
"live": "开播",
|
|
||||||
"offline": "停播",
|
|
||||||
"risk": "风控",
|
|
||||||
"shorts_fail": "Shorts 失败",
|
|
||||||
"shorts_ok": "Shorts 成功",
|
|
||||||
"shorts_quota": "Shorts 配额",
|
|
||||||
"tiktok_fail": "TikTok 失败",
|
|
||||||
"tiktok_ok": "TikTok 成功",
|
|
||||||
"tiktok_limit": "TikTok 限额",
|
|
||||||
"watch_remind": "提醒",
|
|
||||||
"ops": "运维",
|
|
||||||
}
|
|
||||||
title = title_map.get(event, event)
|
|
||||||
message = str(payload.get("message") or event)
|
|
||||||
tags = "rotating_light" if event in {"risk", "shorts_fail", "tiktok_fail"} else "bell"
|
|
||||||
priority = "high" if event in {"risk", "shorts_fail", "tiktok_fail"} else "default"
|
|
||||||
|
|
||||||
def _send() -> None:
|
|
||||||
try:
|
|
||||||
ops_panel.send_ntfy(title, message, priority, tags)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
|
||||||
asyncio.get_running_loop()
|
|
||||||
asyncio.create_task(asyncio.to_thread(_send))
|
|
||||||
except RuntimeError:
|
|
||||||
await asyncio.to_thread(_send)
|
|
||||||
|
|
||||||
|
|
||||||
async def send_webhook(event: str, payload: dict[str, Any]) -> None:
|
async def send_webhook(event: str, payload: dict[str, Any]) -> None:
|
||||||
|
"""Existing webhook notifier — unchanged behavior (ops/ntfy is a separate module)."""
|
||||||
cfg = db.get_settings_map()
|
cfg = db.get_settings_map()
|
||||||
if not _event_allowed(event, cfg):
|
|
||||||
return
|
|
||||||
|
|
||||||
# ntfy mirror (does not require webhook URL)
|
|
||||||
await send_ntfy_best_effort(event, payload)
|
|
||||||
|
|
||||||
url = str(cfg.get("notify_webhook_url") or "").strip()
|
url = str(cfg.get("notify_webhook_url") or "").strip()
|
||||||
if not url:
|
if not url:
|
||||||
return
|
return
|
||||||
|
if event == "live" and not cfg.get("notify_on_live", True):
|
||||||
|
return
|
||||||
|
if event == "offline" and not cfg.get("notify_on_offline", False):
|
||||||
|
return
|
||||||
|
if event == "risk" and not cfg.get("notify_on_risk", True):
|
||||||
|
return
|
||||||
|
if event == "shorts_fail" and not cfg.get("notify_on_shorts_fail", True):
|
||||||
|
return
|
||||||
|
if event == "shorts_ok" and not cfg.get("notify_on_shorts_ok", False):
|
||||||
|
return
|
||||||
|
if event == "shorts_quota" and not cfg.get("notify_on_shorts_quota", True):
|
||||||
|
return
|
||||||
|
if event == "tiktok_fail" and not cfg.get("notify_on_tiktok_fail", True):
|
||||||
|
return
|
||||||
|
if event == "tiktok_ok" and not cfg.get("notify_on_tiktok_ok", False):
|
||||||
|
return
|
||||||
|
if event == "tiktok_limit" and not cfg.get("notify_on_tiktok_limit", True):
|
||||||
|
return
|
||||||
|
if event == "watch_remind" and not cfg.get("notify_on_watch_remind", True):
|
||||||
|
return
|
||||||
|
# allow ops/test always when URL configured
|
||||||
|
|
||||||
body = {
|
body = {
|
||||||
"event": event,
|
"event": event,
|
||||||
|
|||||||
@ -51,8 +51,8 @@ export default function RootLayout({ children }: { children: React.ReactNode })
|
|||||||
<script
|
<script
|
||||||
defer
|
defer
|
||||||
src="https://umami.nomadro.com/script.js"
|
src="https://umami.nomadro.com/script.js"
|
||||||
data-website-id={process.env.NEXT_PUBLIC_UMAMI_WEBSITE_ID || "f18d3484-be2e-4344-8882-b80c5b53f9cf"}
|
data-website-id="f18d3484-be2e-4344-8882-b80c5b53f9cf"
|
||||||
/>
|
></script>
|
||||||
</head>
|
</head>
|
||||||
<body className="min-h-[100dvh] antialiased">
|
<body className="min-h-[100dvh] antialiased">
|
||||||
<Providers>{children}</Providers>
|
<Providers>{children}</Providers>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user