Skip to content

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

fix: allow s3 files to download

Marc Seitz53697b533bb0
diff --git a/lib/files/get-file.ts b/lib/files/get-file.ts
index 46c4b9d2..eb46f581 100644
--- a/lib/files/get-file.ts
+++ b/lib/files/get-file.ts
@@ -1,17 +1,29 @@
import { match } from "ts-pattern";
import { DocumentStorageType } from "@prisma/client";
+import { getDownloadUrl } from "@vercel/blob";
export type GetFileOptions = {
type: DocumentStorageType;
data: string;
+ isDownload?: boolean;
};
-export const getFile = async ({ type, data }: GetFileOptions) => {
+export const getFile = async ({
+ type,
+ data,
+ isDownload = false,
+}: GetFileOptions) => {
console.log("type", type);
const url = await match(type)
- .with(DocumentStorageType.VERCEL_BLOB, () => data)
+ .with(DocumentStorageType.VERCEL_BLOB, () => {
+ if (isDownload) {
+ return getDownloadUrl(data);
+ } else {
+ return data;
+ }
+ })
.with(DocumentStorageType.S3_PATH, async () => getFileFromS3(data))
.exhaustive();
diff --git a/pages/api/links/download.ts b/pages/api/links/download.ts
index bd92389c..6653ada6 100644
--- a/pages/api/links/download.ts
+++ b/pages/api/links/download.ts
@@ -1,6 +1,6 @@
import { NextApiRequest, NextApiResponse } from "next";
import prisma from "@/lib/prisma";
-import { getDownloadUrl } from "@vercel/blob";
+import { getFile } from "@/lib/files/get-file";
export default async function handle(
req: NextApiRequest,
@@ -33,6 +33,7 @@ export default async function handle(
select: {
type: true,
file: true,
+ storageType: true,
},
take: 1,
},
@@ -80,7 +81,11 @@ export default async function handle(
data: { downloadedAt: new Date() },
});
- const downloadUrl = getDownloadUrl(view.document.versions[0].file);
+ const downloadUrl = await getFile({
+ type: view.document.versions[0].storageType,
+ data: view.document.versions[0].file,
+ isDownload: true,
+ });
return res.status(200).json({ downloadUrl });
} catch (error) {