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 | |
| parent | 64f24acb9a1835ea7f0bec241c233c3e4a202d46 (diff) | |
| download | karakeep-cddaefd9420507318d71f56355ff5a6648dcd951.tar.zst | |
feat: Change webhooks to be configurable by users
Diffstat (limited to 'apps/workers')
| -rw-r--r-- | apps/workers/crawlerWorker.ts | 4 | ||||
| -rw-r--r-- | apps/workers/webhookWorker.ts | 21 |
2 files changed, 14 insertions, 11 deletions
diff --git a/apps/workers/crawlerWorker.ts b/apps/workers/crawlerWorker.ts index 9666299d..6bb4f4ac 100644 --- a/apps/workers/crawlerWorker.ts +++ b/apps/workers/crawlerWorker.ts @@ -55,7 +55,7 @@ import { OpenAIQueue, triggerSearchReindex, triggerVideoWorker, - triggerWebhookWorker, + triggerWebhook, zCrawlLinkRequestSchema, } from "@hoarder/shared/queues"; import { BookmarkTypes } from "@hoarder/shared/types/bookmarks"; @@ -772,7 +772,7 @@ async function runCrawler(job: DequeuedJob<ZCrawlLinkRequest>) { await triggerVideoWorker(bookmarkId, url); // Trigger a webhook - await triggerWebhookWorker(bookmarkId, "crawled"); + await triggerWebhook(bookmarkId, "crawled"); // Do the archival as a separate last step as it has the potential for failure await archivalLogic(); 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; |
