Webhooks
用于 link.visit、link.download 和 link.play 的 HTTPS 端点,由 Svix 负责投递。
仅支持 HTTPS 端点,不允许使用 localhost 或私有 IP。每个账户最多 10 个。
事件:link.visit、link.download、link.play。密钥格式为 whsec_…,仅在创建或轮换时显示一次,请妥善保存。切勿将其放入 JSON 请求体中。
CLI
linkdash webhooks create --url https://example.com/hooks
linkdash webhooks list
linkdash webhooks get <id>
linkdash webhooks rotate <id>
linkdash webhooks delete <id>
list 和 get 只返回 secretHint(whsec_…xxxx)。
HTTP
curl https://api.linkdash.dev/v1/webhooks \
-X POST \
-H "Authorization: Bearer ldash_..." \
-H "Content-Type: application/json" \
-d '{"url":"https://example.com/hooks"}'
GET /webhooks、POST /webhooks、GET /webhooks/:id、DELETE /webhooks/:id、POST /webhooks/:id/rotate。
负载
{
"type": "link.visit",
"timestamp": "2026-08-17T16:00:00.000Z",
"data": { "id": "deck", "kind": "file", "variant": "main", "country": "DE", "referrer": "…" }
}
data.variant 表示访问者实际获得的变体(单变体链接为 main)。
每次投递都会携带以下请求头(Svix 重试时沿用同一个 id):
svix-idsvix-timestamp(Unix 时间戳,单位为秒)svix-signature(v1,<base64 hmac>)
签名内容:对 {id}.{timestamp}.{raw body} 进行 HMAC-SHA256 计算。密钥格式为 whsec_ + base64。
验证
投递由 Svix 发送,遵循 Standard Webhooks 规范。请使用 svix 包进行验证(与 Clerk 和 Resend 相同)。
npm i svix
import { Webhook, WebhookVerificationError } from "svix";
const wh = new Webhook(process.env.LINKDASH_WEBHOOK_SECRET); // whsec_… shown once
try {
const event = wh.verify(rawBody, {
"svix-id": headers["svix-id"],
"svix-timestamp": headers["svix-timestamp"],
"svix-signature": headers["svix-signature"],
});
// event.type is "link.visit" | "link.download" | "link.play"
} catch (err) {
if (err instanceof WebhookVerificationError) {
// 400 — do not process
}
throw err;
}
