Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

mobile: do not cleanup documents from cache after download

ammarahm-ed675e1e2c6fbf
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 <http://www.gnu.org/licenses/>.
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);
}
}