From 675e1e2c6fbfb0c39ca10188d03532d122222d5c Mon Sep 17 00:00:00 2001 From: ammarahm-ed Date: Thu, 25 May 2023 12:38:55 +0500 Subject: [PATCH] mobile: do not cleanup documents from cache after download --- apps/mobile/app/common/filesystem/download-attachment.js | 9 +++++++-- apps/mobile/app/common/filesystem/upload.js | 7 +++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/apps/mobile/app/common/filesystem/download-attachment.js b/apps/mobile/app/common/filesystem/download-attachment.js index 3c0b01243..34ca2c5a4 100644 --- a/apps/mobile/app/common/filesystem/download-attachment.js +++ b/apps/mobile/app/common/filesystem/download-attachment.js @@ -20,7 +20,8 @@ along with this program. If not, see . import Sodium from "@ammarahmed/react-native-sodium"; import { getFileNameWithExtension, - isImage + isImage, + isDocument } from "@notesnook/core/utils/filename"; import React from "react"; import { Platform } from "react-native"; @@ -245,7 +246,11 @@ export default async function downloadAttachment( }); } - if (attachment.dateUploaded && !isImage(attachment.metadata?.type)) { + if ( + attachment.dateUploaded && + !isImage(attachment.metadata?.type) && + !isDocument(attachment.metadata?.type) + ) { RNFetchBlob.fs .unlink(RNFetchBlob.fs.dirs.CacheDir + `/${attachment.metadata.hash}`) .catch(console.log); diff --git a/apps/mobile/app/common/filesystem/upload.js b/apps/mobile/app/common/filesystem/upload.js index acd3b5cb1..e362ac2bb 100644 --- a/apps/mobile/app/common/filesystem/upload.js +++ b/apps/mobile/app/common/filesystem/upload.js @@ -21,7 +21,7 @@ import RNFetchBlob from "react-native-blob-util"; import { useAttachmentStore } from "../../stores/use-attachment-store"; import { db } from "../database"; import { cacheDir } from "./utils"; -import { isImage } from "@notesnook/core/utils/filename"; +import { isImage, isDocument } from "@notesnook/core/utils/filename"; export async function uploadFile(filename, data, cancelToken) { if (!data) return false; @@ -64,7 +64,10 @@ export async function uploadFile(filename, data, cancelToken) { if (result) { let attachment = db.attachments.attachment(filename); if (!attachment) return result; - if (!isImage(attachment.metadata.type)) { + if ( + !isImage(attachment.metadata.type) && + !isDocument(attachment.metadata?.type) + ) { RNFetchBlob.fs.unlink(`${cacheDir}/${filename}`).catch(console.log); } }