From c83e6a92df8c9e972ad31f323aaf17dab645cbe3 Mon Sep 17 00:00:00 2001 From: Aamir Azad Date: Mon, 12 Aug 2024 09:07:32 -0400 Subject: [PATCH] Start work on getting the thumbnail for each one --- src/app/paperless/page.tsx | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/app/paperless/page.tsx b/src/app/paperless/page.tsx index 8ffb972..138ba3a 100644 --- a/src/app/paperless/page.tsx +++ b/src/app/paperless/page.tsx @@ -26,6 +26,7 @@ import { getUserData } from "@/app/actions"; import Link from "next/link"; import OpenInternalLink from "@/components/internal-link"; import type { PaperlessDocumentsType } from "@/types"; +import { UsersTableType } from "@/server/db/schema"; const queryClient = new QueryClient(); @@ -50,6 +51,31 @@ async function getPaperlessDocuments(query: string) { return data; } +export async function getPaperlessThumbnail( + documentId: number, + userData: UsersTableType, +): Promise { + try { + const url = `${userData.paperlessURL}/api/documents/${documentId}/thumb/`; + const response = await fetch(url, { + headers: { + Authorization: `Token ${userData.paperlessToken}`, + }, + }); + if (response.ok) { + const blob = await response.blob(); + const objectUrl = URL.createObjectURL(blob); + return objectUrl; + } else { + console.error("Failed to fetch PDF"); + return null; + } + } catch (error) { + console.error("Error fetching PDF:", error); + return null; + } +} + function DocumentsSearch() { const formSchema = z.object({ query: z.string().min(3).max(256),