Skip to content

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

fix: define server-side `File` type

Marc Seitzadfda23ba521
diff --git a/lib/files/put-file-server.ts b/lib/files/put-file-server.ts
index 32fab2f0..a26048f9 100644
--- a/lib/files/put-file-server.ts
+++ b/lib/files/put-file-server.ts
@@ -8,6 +8,13 @@ import { getS3Client } from "./aws-client";
import slugify from "@sindresorhus/slugify";
import path from "node:path";
+// `File` is a web API type and not available server-side, so we need to define our own type
+type File = {
+ name: string;
+ type: string;
+ buffer: Buffer;
+};
+
export const putFileServer = async ({
file,
teamId,
@@ -34,7 +41,7 @@ export const putFileServer = async ({
};
const putFileInVercelServer = async (file: File) => {
- const contents = await file.arrayBuffer();
+ const contents = file.buffer;
const blob = await put(file.name, contents, {
access: "public",
@@ -66,8 +73,7 @@ const putFileInS3Server = async ({
const key = `${teamId}/${docId}/${slugify(name)}${ext}`;
- const arrayBuffer = await file.arrayBuffer();
- const buffer = Buffer.from(arrayBuffer);
+ const buffer = file.buffer;
const params = {
Bucket: process.env.NEXT_PRIVATE_UPLOAD_BUCKET,
diff --git a/pages/api/mupdf/convert-page.ts b/pages/api/mupdf/convert-page.ts
index 8b4f4d67..25fe6b6a 100644
--- a/pages/api/mupdf/convert-page.ts
+++ b/pages/api/mupdf/convert-page.ts
@@ -57,16 +57,18 @@ export default async (req: NextApiRequest, res: NextApiResponse) => {
var pngBuffer = pixmap.asPNG(); // as PNG
+ const buffer = Buffer.from(pngBuffer);
+
// get docId from url with starts with "doc_" with regex
const match = url.match(/(doc_[^\/]+)\//);
const docId = match ? match[1] : undefined;
- const constructedFile = new File([pngBuffer], `page-${pageNumber}.png`, {
- type: "image/png",
- });
-
const { type, data } = await putFileServer({
- file: constructedFile,
+ file: {
+ name: `page-${pageNumber}.png`,
+ type: "image/png",
+ buffer: buffer,
+ },
teamId: teamId,
docId: docId,
});