aboutsummaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
author玄猫 <hanguofeng@gmail.com>2025-01-19 20:34:42 +0800
committerGitHub <noreply@github.com>2025-01-19 12:34:42 +0000
commitb9cce5d12baa40deb21ab4f36be19e3a41e18ad4 (patch)
treef4ec46c026c35ec2c70393b92f52b87e468746ef /packages
parentb323573047dee4c358f513fbb9b50174e9e98a99 (diff)
downloadkarakeep-b9cce5d12baa40deb21ab4f36be19e3a41e18ad4.tar.zst
feat(webhook): Implement webhook functionality for bookmark events (#852)
* feat(webhook): Implement webhook functionality for bookmark events - Added WebhookWorker to handle webhook requests. - Integrated webhook triggering in crawlerWorker after video processing. - Updated main worker initialization to include WebhookWorker. - Enhanced configuration to support webhook URLs, token, and timeout. - Documented webhook configuration options in the documentation. - Introduced zWebhookRequestSchema for validating webhook requests. * feat(webhook): Update webhook handling and configuration - Changed webhook operation type from "create" to "crawled" in crawlerWorker and documentation. - Enhanced webhook retry logic in WebhookWorker to support multiple attempts. - Updated Docker configuration to include new webhook environment variables. - Improved validation for webhook configuration in shared config. - Adjusted zWebhookRequestSchema to reflect the new operation type. - Updated documentation to clarify webhook configuration options and usage. * minor modifications --------- Co-authored-by: Mohamed Bassem <me@mbassem.com>
Diffstat (limited to 'packages')
-rw-r--r--packages/shared/config.ts14
-rw-r--r--packages/shared/queues.ts27
2 files changed, 41 insertions, 0 deletions
diff --git a/packages/shared/config.ts b/packages/shared/config.ts
index 7b74fc21..df9a5764 100644
--- a/packages/shared/config.ts
+++ b/packages/shared/config.ts
@@ -56,6 +56,14 @@ const allEnv = z.object({
DATA_DIR: z.string().default(""),
MAX_ASSET_SIZE_MB: z.coerce.number().default(4),
INFERENCE_LANG: z.string().default("english"),
+ WEBHOOK_URLS: z
+ .string()
+ .transform((val) => val.split(","))
+ .pipe(z.array(z.string().url()))
+ .optional(),
+ WEBHOOK_TOKEN: z.string().optional(),
+ WEBHOOK_TIMEOUT_SEC: z.coerce.number().default(5),
+ WEBHOOK_RETRY_TIMES: z.coerce.number().int().min(0).default(3),
// Build only flag
SERVER_VERSION: z.string().optional(),
DISABLE_NEW_RELEASE_CHECK: stringBool("false"),
@@ -134,6 +142,12 @@ const serverConfigSchema = allEnv.transform((val) => {
serverVersion: val.SERVER_VERSION,
disableNewReleaseCheck: val.DISABLE_NEW_RELEASE_CHECK,
usingLegacySeparateContainers: val.USING_LEGACY_SEPARATE_CONTAINERS,
+ webhook: {
+ urls: val.WEBHOOK_URLS,
+ token: val.WEBHOOK_TOKEN,
+ timeoutSec: val.WEBHOOK_TIMEOUT_SEC,
+ retryTimes: val.WEBHOOK_RETRY_TIMES,
+ },
};
});
diff --git a/packages/shared/queues.ts b/packages/shared/queues.ts
index 7afb8774..b0002a29 100644
--- a/packages/shared/queues.ts
+++ b/packages/shared/queues.ts
@@ -158,3 +158,30 @@ export const AssetPreprocessingQueue =
keepFailedJobs: false,
},
);
+
+//Webhook worker
+export const zWebhookRequestSchema = z.object({
+ bookmarkId: z.string(),
+ operation: z.enum(["crawled"]),
+});
+export type ZWebhookRequest = z.infer<typeof zWebhookRequestSchema>;
+export const WebhookQueue = new SqliteQueue<ZWebhookRequest>(
+ "webhook_queue",
+ queueDB,
+ {
+ defaultJobArgs: {
+ numRetries: 3,
+ },
+ keepFailedJobs: false,
+ },
+);
+
+export async function triggerWebhookWorker(
+ bookmarkId: string,
+ operation: "crawled",
+) {
+ await WebhookQueue.enqueue({
+ bookmarkId,
+ operation,
+ });
+}