From 02bf88252c884eb26fae72b2e5bdcd437bde6c43 Mon Sep 17 00:00:00 2001 From: Ammar Ahmed Date: Tue, 12 Mar 2024 11:49:42 +0500 Subject: [PATCH] mobile: fix attachment exists check when uploading file --- apps/mobile/app/screens/editor/tiptap/picker.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/mobile/app/screens/editor/tiptap/picker.js b/apps/mobile/app/screens/editor/tiptap/picker.js index 5332d5008..36b2bf145 100644 --- a/apps/mobile/app/screens/editor/tiptap/picker.js +++ b/apps/mobile/app/screens/editor/tiptap/picker.js @@ -23,7 +23,7 @@ import { Platform } from "react-native"; import RNFetchBlob from "react-native-blob-util"; import DocumentPicker from "react-native-document-picker"; import { launchCamera, launchImageLibrary } from "react-native-image-picker"; -import { db } from "../../../common/database"; +import { DatabaseLogger, db } from "../../../common/database"; import filesystem from "../../../common/filesystem"; import { compressToFile } from "../../../common/filesystem/compress"; import AttachImage from "../../../components/dialogs/attach-image-dialog"; @@ -290,13 +290,15 @@ const handleImageResponse = async (response, options) => { }); let fileName = image.originalFileName || image.fileName; + console.log("attaching file..."); if (!(await attachFile(uri, hash, image.type, fileName, options))) return; if (Platform.OS === "ios") await RNFetchBlob.fs.unlink(uri); - + console.log("attaching image to note..."); if ( useTabStore.getState().getNoteIdForTab(options.tabId) === options.noteId ) { + console.log("attaching image to note..."); editorController.current?.commands.insertImage( { hash: hash, @@ -330,9 +332,8 @@ const handleImageResponse = async (response, options) => { */ export async function attachFile(uri, hash, type, filename, options) { try { - let exists = db.attachments.exists(hash); + let exists = await db.attachments.exists(hash); let encryptionInfo; - if (options?.hash && options.hash !== hash) { ToastManager.show({ heading: "Please select the same file for reuploading", @@ -364,10 +365,9 @@ export async function attachFile(uri, hash, type, filename, options) { encryptionInfo = { hash: hash }; } await db.attachments.add(encryptionInfo, options.noteId); - return true; } catch (e) { - console.log("attach file error: ", e); + DatabaseLogger.error(e); if (Platform.OS === "ios") { await RNFetchBlob.fs.unlink(uri); }