Skip to content

Commit

Permalink
Start work on getting the thumbnail for each one
Browse files Browse the repository at this point in the history
  • Loading branch information
aamirazad committed Aug 12, 2024
1 parent ec02d9e commit c83e6a9
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/app/paperless/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -50,6 +51,31 @@ async function getPaperlessDocuments(query: string) {
return data;
}

export async function getPaperlessThumbnail(
documentId: number,
userData: UsersTableType,
): Promise<string | null> {
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),
Expand Down

0 comments on commit c83e6a9

Please sign in to comment.