From baf48af5f0a4b88642edc18ae8b16e81260e1846 Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 6 Feb 2024 18:16:35 +0000 Subject: Implement metadata fetching logic in the crawler --- web/app/api/v1/links/route.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'web/app/api') diff --git a/web/app/api/v1/links/route.ts b/web/app/api/v1/links/route.ts index 97bfa3de..990b6c02 100644 --- a/web/app/api/v1/links/route.ts +++ b/web/app/api/v1/links/route.ts @@ -1,7 +1,9 @@ import { authOptions } from "@/lib/auth"; -import prisma from "@/lib/prisma"; +import { LinkCrawlerQueue } from "@remember/shared/queues"; +import prisma from "@remember/db"; + import { - ZNewBookmarkedLinkRequest, + zNewBookmarkedLinkRequestSchema, ZGetLinksResponse, ZBookmarkedLink, } from "@/lib/types/api/links"; @@ -15,7 +17,9 @@ export async function POST(request: NextRequest) { return new Response(null, { status: 401 }); } - const linkRequest = ZNewBookmarkedLinkRequest.safeParse(await request.json()); + const linkRequest = zNewBookmarkedLinkRequestSchema.safeParse( + await request.json(), + ); if (!linkRequest.success) { return NextResponse.json( @@ -33,8 +37,13 @@ export async function POST(request: NextRequest) { }, }); - let response: ZBookmarkedLink = { ...link }; + // Enqueue crawling request + await LinkCrawlerQueue.add("crawl", { + linkId: link.id, + url: link.url, + }); + let response: ZBookmarkedLink = { ...link }; return NextResponse.json(response, { status: 201 }); } @@ -57,6 +66,7 @@ export async function GET() { title: true, description: true, imageUrl: true, + favicon: true, }, }, }, -- cgit v1.2.3-70-g09d2