mobile: do not cleanup documents from cache after download

This commit is contained in:
ammarahm-ed
2023-05-25 12:38:55 +05:00
committed by Abdullah Atta
parent 0f7f3bae7e
commit 675e1e2c6f
2 changed files with 12 additions and 4 deletions

View File

@@ -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);

View File

@@ -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);
}
}