From 50c3c5e132643fc33d39fb9dc1fe951efe766337 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Wed, 14 Feb 2024 01:26:45 +0000 Subject: feature: Add ability to refresh bookmark details --- packages/workers/crawler.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'packages/workers/crawler.ts') diff --git a/packages/workers/crawler.ts b/packages/workers/crawler.ts index 45d2f530..4febc1ca 100644 --- a/packages/workers/crawler.ts +++ b/packages/workers/crawler.ts @@ -70,6 +70,17 @@ export class CrawlerWorker { } } +async function getBookmarkUrl(bookmarkId: string) { + const bookmark = await prisma.bookmarkedLink.findUnique({ + where: { id: bookmarkId }, + }); + + if (!bookmark) { + throw new Error("The bookmark either doesn't exist or not a link"); + } + return bookmark.url; +} + async function crawlPage(url: string) { if (!browser) { throw new Error("The browser must have been initalized by this point."); @@ -98,7 +109,8 @@ async function runCrawler(job: Job) { return; } - const { url, bookmarkId } = request.data; + const { bookmarkId } = request.data; + const url = await getBookmarkUrl(bookmarkId); logger.info( `[Crawler][${jobId}] Will crawl "${url}" for link with id "${bookmarkId}"`, -- cgit v1.2.3-70-g09d2