Skip to content

Papermark is the open-source DocSend alternative and secure data rooms with built-in analytics and custom domains.

fix: papermark assistant works with s3 documents

Marc Seitz44d9e3957928
diff --git a/components/chat/empty-screen.tsx b/components/chat/empty-screen.tsx
index 1da767f9..1ed716c4 100644
--- a/components/chat/empty-screen.tsx
+++ b/components/chat/empty-screen.tsx
@@ -41,13 +41,22 @@ export function EmptyScreen({
<div className="mx-auto w-1/2 md:w-1/3">
<div className="flex items-center justify-center">
{firstPage ? (
- <Image
- src={firstPage}
- width={768}
- height={100}
- className="object-contain rounded-md ring-1 ring-gray-700"
- alt="First page of the document"
- />
+ firstPage.includes("cloudfront.net") ? (
+ <img
+ className="object-contain rounded-md ring-1 ring-gray-700"
+ src={firstPage}
+ alt={`Page 1`}
+ fetchPriority="high"
+ />
+ ) : (
+ <Image
+ src={firstPage}
+ width={768}
+ height={100}
+ className="object-contain rounded-md ring-1 ring-gray-700"
+ alt="First page of the document"
+ />
+ )
) : (
<div className="flex items-center justify-center rounded-md w-full">
<p className="text-2xl text-center">
diff --git a/pages/api/assistants/index.ts b/pages/api/assistants/index.ts
index 3364b9f3..fd56f1f0 100644
--- a/pages/api/assistants/index.ts
+++ b/pages/api/assistants/index.ts
@@ -4,6 +4,7 @@ import prisma from "@/lib/prisma";
import { authOptions } from "../auth/[...nextauth]";
import { errorhandler } from "@/lib/errorHandler";
import { openai } from "@/lib/openai";
+import { getFile } from "@/lib/files/get-file";
export default async function handle(
req: NextApiRequest,
@@ -32,6 +33,7 @@ export default async function handle(
id: true,
fileId: true,
file: true,
+ storageType: true,
},
},
},
@@ -50,7 +52,12 @@ export default async function handle(
// Upload the file to OpenAI
const fileId = (
await openai.files.create({
- file: await fetch(document.versions[0].file),
+ file: await fetch(
+ await getFile({
+ type: document.versions[0].storageType,
+ data: document.versions[0].file,
+ }),
+ ),
purpose: "assistants",
})
).id;
diff --git a/pages/documents/[id]/chat.tsx b/pages/documents/[id]/chat.tsx
index 8f7bb1be..271773ff 100644
--- a/pages/documents/[id]/chat.tsx
+++ b/pages/documents/[id]/chat.tsx
@@ -10,6 +10,7 @@ import { Button } from "@/components/ui/button";
import Link from "next/link";
import { usePlausible } from "next-plausible";
import { useEffect } from "react";
+import { getFile } from "@/lib/files/get-file";
export const getServerSideProps = async (context: any) => {
const { id } = context.params;
@@ -19,7 +20,7 @@ export const getServerSideProps = async (context: any) => {
return {
redirect: {
permanent: false,
- destination: `/login?next=/view/${id}/chat`,
+ destination: `/login?next=/documents/${id}/chat`,
},
};
}
@@ -48,6 +49,7 @@ export const getServerSideProps = async (context: any) => {
where: { pageNumber: 1 },
select: {
file: true,
+ storageType: true,
},
},
},
@@ -84,11 +86,18 @@ export const getServerSideProps = async (context: any) => {
const { threadId, messages } = await res.json();
+ const firstPage = document.versions[0].pages[0]
+ ? await getFile({
+ type: document.versions[0].pages[0].storageType,
+ data: document.versions[0].pages[0].file,
+ })
+ : "";
+
return {
props: {
threadId,
messages: messages || [],
- firstPage: document.versions[0].pages[0]?.file || "",
+ firstPage,
userId,
documentId: document.id,
},
diff --git a/pages/view/[linkId]/chat.tsx b/pages/view/[linkId]/chat.tsx
index 0d2a1c75..e49b379d 100644
--- a/pages/view/[linkId]/chat.tsx
+++ b/pages/view/[linkId]/chat.tsx
@@ -10,6 +10,7 @@ import Link from "next/link";
import { Button } from "@/components/ui/button";
import { usePlausible } from "next-plausible";
import { useEffect } from "react";
+import { getFile } from "@/lib/files/get-file";
export const getServerSideProps = async (context: any) => {
const { linkId } = context.params;
@@ -38,6 +39,7 @@ export const getServerSideProps = async (context: any) => {
where: { pageNumber: 1 },
select: {
file: true,
+ storageType: true,
},
},
},
@@ -84,11 +86,18 @@ export const getServerSideProps = async (context: any) => {
const { threadId, messages } = await res.json();
+ const firstPage = link.document.versions[0].pages[0]
+ ? await getFile({
+ type: link.document.versions[0].pages[0].storageType,
+ data: link.document.versions[0].pages[0].file,
+ })
+ : "";
+
return {
props: {
threadId,
messages: messages || [],
- firstPage: link.document.versions[0].pages[0]?.file || "",
+ firstPage,
userId: userId,
linkId: linkId,
},