diff options
| author | Mohamed Bassem <me@mbassem.com> | 2025-01-19 13:55:40 +0000 |
|---|---|---|
| committer | Mohamed Bassem <me@mbassem.com> | 2025-01-19 19:06:48 +0000 |
| commit | cddaefd9420507318d71f56355ff5a6648dcd951 (patch) | |
| tree | cf196ef12c36fdb0502b5ebf0f722ab32de8e2c0 /apps/workers/webhookWorker.ts | |
| parent | 64f24acb9a1835ea7f0bec241c233c3e4a202d46 (diff) | |
| download | karakeep-cddaefd9420507318d71f56355ff5a6648dcd951.tar.zst | |
feat: Change webhooks to be configurable by users
Diffstat (limited to 'apps/workers/webhookWorker.ts')
| -rw-r--r-- | apps/workers/webhookWorker.ts | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/apps/workers/webhookWorker.ts b/apps/workers/webhookWorker.ts index 5124f8a4..dec40570 100644 --- a/apps/workers/webhookWorker.ts +++ b/apps/workers/webhookWorker.ts @@ -54,20 +54,17 @@ async function fetchBookmark(linkId: string) { link: true, text: true, asset: true, + user: { + with: { + webhooks: true, + }, + }, }, }); } async function runWebhook(job: DequeuedJob<ZWebhookRequest>) { const jobId = job.id; - const webhookUrls = serverConfig.webhook.urls; - if (!webhookUrls) { - logger.info( - `[webhook][${jobId}] No webhook urls configured. Skipping webhook job.`, - ); - return; - } - const webhookToken = serverConfig.webhook.token; const webhookTimeoutSec = serverConfig.webhook.timeoutSec; const { bookmarkId } = job.data; @@ -78,12 +75,18 @@ async function runWebhook(job: DequeuedJob<ZWebhookRequest>) { ); } + if (!bookmark.user.webhooks) { + return; + } + logger.info( `[webhook][${jobId}] Starting a webhook job for bookmark with id "${bookmark.id}"`, ); await Promise.allSettled( - webhookUrls.map(async (url) => { + bookmark.user.webhooks.map(async (webhook) => { + const url = webhook.url; + const webhookToken = webhook.token; const maxRetries = serverConfig.webhook.retryTimes; let attempt = 0; let success = false; |
