Skip to content

Commit

Permalink
fix: Do not remove all shared files
Browse files Browse the repository at this point in the history
When sharing as an attachment, only files created
for sharing should be deleted.
As a reminder, files are created for sharing when
the user wishes to share only one side of a document.
  • Loading branch information
Merkur39 committed Oct 24, 2024
1 parent 968981b commit 515e734
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/components/Multiselect/ForwardBottomSheet.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export const ForwardBottomSheet = ({ onClose, filesWithPage, shareByLink }) => {
const shareAsAttachment = async () => {
setShowBackdrop(true)
const fileIds = filesWithoutSpecificPage.map(({ file }) => file._id)
const fileIdsToRemove = []
try {
if (filesWithSpecificPage.length > 0) {
const newFiles = await createPdfFileByPage({
Expand All @@ -49,11 +50,12 @@ export const ForwardBottomSheet = ({ onClose, filesWithPage, shareByLink }) => {
})
const tempFileIds = newFiles.map(file => file._id)
fileIds.push(...tempFileIds)
fileIdsToRemove.push(...tempFileIds)
}

await shareFiles(fileIds)

removeFilesPermanently(client, fileIds).catch(error => {
removeFilesPermanently(client, fileIdsToRemove).catch(error => {
log.error(`Error while removing files: ${error}`)
})

Expand All @@ -73,8 +75,8 @@ export const ForwardBottomSheet = ({ onClose, filesWithPage, shareByLink }) => {
} catch (error) {
if (error.message === 'User did not share') return

if (fileIds.length > 0) {
removeFilesPermanently(client, fileIds).catch(error => {
if (fileIdsToRemove.length > 0) {
removeFilesPermanently(client, fileIdsToRemove).catch(error => {
log.error(`Error while removing files in catch: ${error}`)
})
}
Expand Down

0 comments on commit 515e734

Please sign in to comment.