From 927981bf30c87f18ce0629a4703b56ed4bf9b238 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Wed, 28 Jun 2017 12:56:44 +0900 Subject: [PATCH 1/2] Randomize the image name when it's dropped --- browser/main/lib/dataApi/copyImage.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/browser/main/lib/dataApi/copyImage.js b/browser/main/lib/dataApi/copyImage.js index 8c6f1787..f6da5ae2 100644 --- a/browser/main/lib/dataApi/copyImage.js +++ b/browser/main/lib/dataApi/copyImage.js @@ -19,10 +19,12 @@ function copyImage (filePath, storageKey) { const targetStorage = storage const inputImage = fs.createReadStream(filePath) - const imageName = path.basename(filePath) - const outputImage = fs.createWriteStream(path.join(targetStorage.path, 'images', imageName)) + const imageExt = path.extname(filePath) + const imageName = Math.random().toString(36).slice(-16) + const basename = `${imageName}${imageExt}` + const outputImage = fs.createWriteStream(path.join(targetStorage.path, 'images', basename)) inputImage.pipe(outputImage) - resolve(`${encodeURI(targetStorage.path)}/images/${encodeURI(imageName)}`) + resolve(`${encodeURI(targetStorage.path)}/images/${encodeURI(basename)}`) } catch (e) { return reject(e) } From 032b5a59f22410cb6e6514d7ad918a04a382d164 Mon Sep 17 00:00:00 2001 From: asmsuechan Date: Sat, 1 Jul 2017 18:07:16 +0900 Subject: [PATCH 2/2] Remove encodeURI --- browser/components/CodeEditor.js | 2 +- browser/main/lib/dataApi/copyImage.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/browser/components/CodeEditor.js b/browser/components/CodeEditor.js index 995542a0..1714e281 100644 --- a/browser/components/CodeEditor.js +++ b/browser/components/CodeEditor.js @@ -193,7 +193,7 @@ export default class CodeEditor extends React.Component { const filename = path.basename(imagePath) copyImage(imagePath, this.props.storageKey).then((imagePathInTheStorage) => { - const imageMd = `![${encodeURI(filename)}](${imagePathInTheStorage})` + const imageMd = `![${filename}](${imagePathInTheStorage})` this.insertImageMd(imageMd) }) } diff --git a/browser/main/lib/dataApi/copyImage.js b/browser/main/lib/dataApi/copyImage.js index f6da5ae2..dfd72476 100644 --- a/browser/main/lib/dataApi/copyImage.js +++ b/browser/main/lib/dataApi/copyImage.js @@ -24,7 +24,7 @@ function copyImage (filePath, storageKey) { const basename = `${imageName}${imageExt}` const outputImage = fs.createWriteStream(path.join(targetStorage.path, 'images', basename)) inputImage.pipe(outputImage) - resolve(`${encodeURI(targetStorage.path)}/images/${encodeURI(basename)}`) + resolve(`${targetStorage.path}/images/${basename}`) } catch (e) { return reject(e) }