diff options
| author | MohamedBassem <me@mbassem.com> | 2024-02-06 18:16:35 +0000 |
|---|---|---|
| committer | MohamedBassem <me@mbassem.com> | 2024-02-06 19:24:52 +0000 |
| commit | baf48af5f0a4b88642edc18ae8b16e81260e1846 (patch) | |
| tree | 1f9779ac76b21ba7504ec664f05064d1b4e9ff2a /web/app/api | |
| parent | e035c2fd1067a06d4774c64ae54548f664490f9d (diff) | |
| download | karakeep-baf48af5f0a4b88642edc18ae8b16e81260e1846.tar.zst | |
Implement metadata fetching logic in the crawler
Diffstat (limited to 'web/app/api')
| -rw-r--r-- | web/app/api/v1/links/route.ts | 18 |
1 files changed, 14 insertions, 4 deletions
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, }, }, }, |
