Skip to content

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

fix: allow deleting web-link documents

Marc Seitz4d6b99131aa6
diff --git a/pages/api/teams/[teamId]/documents/[id]/index.ts b/pages/api/teams/[teamId]/documents/[id]/index.ts
index 8a5cc9bb..2161361f 100644
--- a/pages/api/teams/[teamId]/documents/[id]/index.ts
+++ b/pages/api/teams/[teamId]/documents/[id]/index.ts
@@ -324,8 +324,13 @@ export default async function handle(
return res.status(404).json({ message: "Document not found" });
}
- //if it is not notion document then only delete the document from storage
- if (documentVersions.type !== "notion") {
+ // Notion and web-link documents don't store any bytes: their `file` holds
+ // an external URL, not a storage object. Skip storage deletion for them
+ // (calling deleteFile on the URL would throw and abort the delete).
+ if (
+ documentVersions.type !== "notion" &&
+ documentVersions.type !== "link"
+ ) {
// delete the files from storage
for (const version of documentVersions.versions) {
await deleteFile({
diff --git a/pages/api/teams/[teamId]/folders/manage/[folderId]/index.ts b/pages/api/teams/[teamId]/folders/manage/[folderId]/index.ts
index 4ad4d206..940a8528 100644
--- a/pages/api/teams/[teamId]/folders/manage/[folderId]/index.ts
+++ b/pages/api/teams/[teamId]/folders/manage/[folderId]/index.ts
@@ -97,12 +97,14 @@ async function deleteFolderAndContents(folderId: string, teamId: string) {
await deleteFolderAndContents(childFolder.id, teamId);
}
- // Delete all documents in the folder
+ // Delete all documents in the folder. Notion and web-link documents store an
+ // external URL rather than a real storage object, so they're excluded from
+ // the storage cleanup below (deleteFile would fail on their URL).
const documents = await prisma.document.findMany({
where: {
folderId: folderId,
type: {
- not: "notion",
+ notIn: ["notion", "link"],
},
},
include: {