"use client"; import { useState } from "react"; export function WebhookControl({ sourceId, configured, automatic = false }: { sourceId: number; configured: boolean; automatic?: boolean }) { const [url, setUrl] = useState(""); const [error, setError] = useState(""); const [notice, setNotice] = useState(""); const [busy, setBusy] = useState(false); async function generate() { setBusy(true); setError(""); setNotice(""); try { const response = await fetch(`/api/sources/${sourceId}/webhook`, { method: "POST", headers: { Accept: "application/json" } }); const body = await response.json(); if (!response.ok) throw new Error(body.error || "無法產生 webhook URL"); if (body.rotated) setNotice("Webhook 已安全輪替。"); else setUrl(body.url); } catch (reason) { setError(reason instanceof Error ? reason.message : "無法產生 webhook URL"); } finally { setBusy(false); } } async function copy() { if (url) await navigator.clipboard.writeText(url); } if (automatic) return

Webhook:已由 Memos 自動設定並驗證簽章。

{notice &&

{notice}

}{error &&

{error}

}
; return

Webhook:{configured ? "已設定" : "尚未設定"}

{url ? <> event.currentTarget.select()} />

請立即複製到 Memos;重新整理後完整密鑰不會再顯示。

: } {error &&

{error}

}
; }