Skip to content

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

add file check when readding uploaded file/image

ammarahm-ed730ba3b0d434
diff --git a/apps/mobile/src/screens/editor/tiny/toolbar/picker.js b/apps/mobile/src/screens/editor/tiny/toolbar/picker.js
index b26f625ee..f012ed207 100644
--- a/apps/mobile/src/screens/editor/tiny/toolbar/picker.js
+++ b/apps/mobile/src/screens/editor/tiny/toolbar/picker.js
@@ -10,6 +10,7 @@ import PremiumService from '../../../../services/premium';
import { editing } from '../../../../utils';
import { db } from '../../../../utils/database';
import { eCloseProgressDialog } from '../../../../utils/events';
+import filesystem from '../../../../utils/filesystem';
import { sleep } from '../../../../utils/time';
import { EditorWebView, getNote } from '../../Functions';
import tiny, { safeKeyboardDismiss } from '../tiny';
@@ -321,7 +322,9 @@ async function attachFile(uri, hash, type, filename, options) {
return false;
}
- if (!exists || options?.reupload) {
+ let fileCheck = exists && (await filesystem.checkAttachment(hash));
+
+ if (!exists || options?.reupload || !fileCheck?.success) {
let key = await db.attachments.generateKey();
encryptionInfo = await Sodium.encryptFile(key, {
uri: uri,
diff --git a/apps/mobile/src/utils/filesystem/download.js b/apps/mobile/src/utils/filesystem/download.js
index f0946c27f..2a077a469 100644
--- a/apps/mobile/src/utils/filesystem/download.js
+++ b/apps/mobile/src/utils/filesystem/download.js
@@ -10,6 +10,7 @@ import { db } from '../database';
import Storage from '../database/storage';
import { cacheDir, fileCheck } from './utils';
import hosts from 'notes-core/utils/constants';
+import NetInfo from '@react-native-community/netinfo';
export async function downloadFile(filename, data, cancelToken) {
if (!data) return false;
@@ -163,6 +164,9 @@ export async function getUploadedFileSize(hash) {
}
export async function checkAttachment(hash) {
+ const internetState = await NetInfo.fetch();
+ const isInternetReachable = internetState.isConnected && internetState.isInternetReachable;
+ if (!isInternetReachable) return { success: true };
const attachment = db.attachments.attachment(hash);
if (!attachment) return { failed: 'Attachment not found.' };
@@ -170,7 +174,7 @@ export async function checkAttachment(hash) {
const size = await getUploadedFileSize(hash);
if (size <= 0) return { failed: 'File length is 0.' };
} catch (e) {
- return { failed: e.message };
+ return { failed: e?.message };
}
return { success: true };
}