Skip to content

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

mobile: use isImage check from core

ammarahm-edb77711a53d63
diff --git a/apps/mobile/app/common/filesystem/download-attachment.js b/apps/mobile/app/common/filesystem/download-attachment.js
index a9e8fb318..1e18ddb73 100644
--- a/apps/mobile/app/common/filesystem/download-attachment.js
+++ b/apps/mobile/app/common/filesystem/download-attachment.js
@@ -18,14 +18,17 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Sodium from "@ammarahmed/react-native-sodium";
-import { getFileNameWithExtension } from "@notesnook/core/utils/filename";
+import {
+ getFileNameWithExtension,
+ isImage
+} from "@notesnook/core/utils/filename";
import React from "react";
import { Platform } from "react-native";
import * as ScopedStorage from "react-native-scoped-storage";
import { subscribe, zip } from "react-native-zip-archive";
import RNFetchBlob from "rn-fetch-blob";
import { ShareComponent } from "../../components/sheets/export-notes/share";
-import { presentSheet, ToastEvent } from "../../services/event-manager";
+import { ToastEvent, presentSheet } from "../../services/event-manager";
import { useAttachmentStore } from "../../stores/use-attachment-store";
import { db } from "../database";
import Storage from "../database/storage";
@@ -242,10 +245,7 @@ export default async function downloadAttachment(
});
}
- if (
- attachment.dateUploaded &&
- !attachment.metadata?.type?.startsWith("image")
- ) {
+ if (attachment.dateUploaded && !isImage(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 c4e4aeef7..edee5406b 100644
--- a/apps/mobile/app/common/filesystem/upload.js
+++ b/apps/mobile/app/common/filesystem/upload.js
@@ -21,6 +21,7 @@ import RNFetchBlob from "rn-fetch-blob";
import { useAttachmentStore } from "../../stores/use-attachment-store";
import { db } from "../database";
import { cacheDir } from "./utils";
+import { isImage } from "@notesnook/core/utils/filename";
export async function uploadFile(filename, data, cancelToken) {
if (!data) return false;
@@ -63,7 +64,7 @@ export async function uploadFile(filename, data, cancelToken) {
if (result) {
let attachment = db.attachments.attachment(filename);
if (!attachment) return result;
- if (!attachment.metadata.type.startsWith("image/")) {
+ if (!isImage(attachment.metadata.type)) {
RNFetchBlob.fs.unlink(`${cacheDir}/${filename}`).catch(console.log);
}
}