From 80b467eeadd2bea5e2f3f3f95cbb61e5e3ccfe6f Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Thu, 3 May 2018 11:31:07 +0100 Subject: [PATCH] All: For now, disable attaching resources larger than 10MB due to #371 --- ElectronClient/app/gui/NoteText.jsx | 1 + ReactNativeClient/lib/components/screens/note.js | 6 ++++++ ReactNativeClient/lib/shim-init-node.js | 3 +++ 3 files changed, 10 insertions(+) diff --git a/ElectronClient/app/gui/NoteText.jsx b/ElectronClient/app/gui/NoteText.jsx index 7e2bdfb3895..a041381b66b 100644 --- a/ElectronClient/app/gui/NoteText.jsx +++ b/ElectronClient/app/gui/NoteText.jsx @@ -530,6 +530,7 @@ class NoteTextComponent extends React.Component { }); } catch (error) { reg.logger().error(error); + bridge().showErrorMessageBox(error.message); } } } diff --git a/ReactNativeClient/lib/components/screens/note.js b/ReactNativeClient/lib/components/screens/note.js index f4388b5a243..2b6111b9eb0 100644 --- a/ReactNativeClient/lib/components/screens/note.js +++ b/ReactNativeClient/lib/components/screens/note.js @@ -364,10 +364,16 @@ class NoteScreenComponent extends BaseScreenComponent { return; } else { await RNFetchBlob.fs.cp(localFilePath, targetPath); + const stat = await shim.fsDriver().stat(targetPath); + if (stat.size >= 10000000) { + await shim.fsDriver().remove(targetPath); + throw new Error('Resources larger than 10 MB are not currently supported as they may crash the mobile applications. The issue is being investigated and will be fixed at a later time.'); + } } } } catch (error) { reg.logger().warn('Could not attach file:', error); + await dialogs.error(this, error.message); return; } diff --git a/ReactNativeClient/lib/shim-init-node.js b/ReactNativeClient/lib/shim-init-node.js index 55ce95dc702..c9f155f9408 100644 --- a/ReactNativeClient/lib/shim-init-node.js +++ b/ReactNativeClient/lib/shim-init-node.js @@ -111,6 +111,9 @@ function shimInit() { if (resource.mime == 'image/jpeg' || resource.mime == 'image/jpg' || resource.mime == 'image/png') { const result = await resizeImage_(filePath, targetPath, resource.mime); } else { + const stat = await shim.fsDriver().stat(filePath); + if (stat.size >= 10000000) throw new Error('Resources larger than 10 MB are not currently supported as they may crash the mobile applications. The issue is being investigated and will be fixed at a later time.'); + await fs.copy(filePath, targetPath, { overwrite: true }); }