mirror of
https://github.com/Elysola/WebHooker.git
synced 2026-11-21 01:23:40 +00:00
fix(webhook): dedup duplicate deliveries, cache HMAC key, pass ExecutionContext
Skip re-processing when the same X-GitHub-Delivery id is seen (KV, 300s TTL) to stop double pushes when both an org and an App webhook target the worker. Pass ExecutionContext through so dispatch runs via waitUntil instead of a fire-and-forget that gets frozen. Cache the imported HMAC key per secret.
This commit is contained in:
3 files changed
+37
-13
No files matched your search
+13
-1
@@ -45,9 +45,21 @@ export function createServer(): Hono<{ Bindings: Env }> {
|
||||
return c.json({ error: "Invalid event" }, 400);
|
||||
}
|
||||
|
||||
const delivery = headers["x-github-delivery"];
|
||||
if (delivery) {
|
||||
const seen = await c.env.KV.get(`delivery:${delivery}`);
|
||||
if (seen) {
|
||||
return c.json({ ok: true, duplicate: true });
|
||||
}
|
||||
await c.env.KV.put(`delivery:${delivery}`, "1", { expirationTtl: 300 });
|
||||
}
|
||||
|
||||
const { loadConfig } = await import("./config");
|
||||
const config = await loadConfig(c.env);
|
||||
dispatchEvent(config, event, c.env).catch((err) => log.error(err, "Dispatch failed"));
|
||||
const dispatch = dispatchEvent(config, event, c.env).catch((err) =>
|
||||
log.error(err, "Dispatch failed"),
|
||||
);
|
||||
c.executionCtx.waitUntil(dispatch);
|
||||
|
||||
return c.json({ ok: true });
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user