Skip to content

Commit 96e91ab

Browse files
committed
convert webhook call to v1
1 parent 064ebfc commit 96e91ab

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

apps/api/src/controllers/v1/crawl.ts

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export async function crawlController(
8181
origin: "api",
8282
crawl_id: id,
8383
sitemapped: true,
84+
v1: true,
8485
},
8586
opts: {
8687
jobId: uuid,
@@ -110,6 +111,7 @@ export async function crawlController(
110111
origin: "api",
111112
crawl_id: id,
112113
webhook: req.body.webhook,
114+
v1: true,
113115
},
114116
{
115117
priority: 15,

apps/api/src/services/queue-worker.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ async function processJob(job: Job, token: string) {
215215
};
216216

217217
if (job.data.mode === "crawl") {
218-
await callWebhook(job.data.team_id, job.id as string, data, job.data.webhook);
218+
await callWebhook(job.data.team_id, job.id as string, data, job.data.webhook, job.data.v1);
219219
}
220220

221221
if (job.data.crawl_id) {
@@ -259,6 +259,7 @@ async function processJob(job: Job, token: string) {
259259
pageOptions: sc.pageOptions,
260260
origin: job.data.origin,
261261
crawl_id: job.data.crawl_id,
262+
v1: job.data.v1,
262263
});
263264

264265
await addCrawlJob(job.data.crawl_id, newJob.id);
@@ -328,7 +329,7 @@ async function processJob(job: Job, token: string) {
328329
docs: fullDocs,
329330
};
330331

331-
await callWebhook(job.data.team_id, job.data.crawl_id, data);
332+
await callWebhook(job.data.team_id, job.data.crawl_id, data, job.data.webhook, job.data.v1);
332333
}
333334
}
334335

@@ -372,7 +373,7 @@ async function processJob(job: Job, token: string) {
372373
};
373374

374375
if (job.data.mode === "crawl" || job.data.crawl_id) {
375-
await callWebhook(job.data.team_id, job.data.crawl_id ?? job.id as string, data);
376+
await callWebhook(job.data.team_id, job.data.crawl_id ?? job.id as string, data, job.data.webhook, job.data.v1);
376377
}
377378

378379
if (job.data.crawl_id) {

apps/api/src/services/webhook.ts

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
import { legacyDocumentConverter } from "../../src/controllers/v1/types";
12
import { Logger } from "../../src/lib/logger";
23
import { supabase_service } from "./supabase";
34

4-
export const callWebhook = async (teamId: string, jobId: string, data: any, specified?: string) => {
5+
export const callWebhook = async (teamId: string, jobId: string, data: any, specified?: string, v1 = false) => {
56
try {
67
const selfHostedUrl = process.env.SELF_HOSTED_WEBHOOK_URL?.replace("{{JOB_ID}}", jobId);
78
const useDbAuthentication = process.env.USE_DB_AUTHENTICATION === 'true';
@@ -30,11 +31,15 @@ export const callWebhook = async (teamId: string, jobId: string, data: any, spec
3031
let dataToSend = [];
3132
if (data.result.links && data.result.links.length !== 0) {
3233
for (let i = 0; i < data.result.links.length; i++) {
33-
dataToSend.push({
34-
content: data.result.links[i].content.content,
35-
markdown: data.result.links[i].content.markdown,
36-
metadata: data.result.links[i].content.metadata,
37-
});
34+
if (v1) {
35+
dataToSend.push(legacyDocumentConverter(data.result.links[i].content))
36+
} else {
37+
dataToSend.push({
38+
content: data.result.links[i].content.content,
39+
markdown: data.result.links[i].content.markdown,
40+
metadata: data.result.links[i].content.metadata,
41+
});
42+
}
3843
}
3944
}
4045

apps/api/src/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export interface WebScraperOptions {
3131
crawl_id?: string;
3232
sitemapped?: boolean;
3333
webhook?: string;
34+
v1?: boolean;
3435
}
3536

3637
export interface RunWebScraperParams {

0 commit comments

Comments
 (0)