From 35ffbea06baaa910412ad480f27afbd2df8ba9d4 Mon Sep 17 00:00:00 2001 From: silverwind Date: Wed, 28 Oct 2020 18:17:56 +0100 Subject: [PATCH] always use 'image' as name for pasted images Some browsers seem to put file system paths into blob.name which look rather odd and should not be part of the posted content. Always set name to static "image" like GH does. --- web_src/js/index.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/web_src/js/index.js b/web_src/js/index.js index cdabffe04d1c0..88c4d3535c2f1 100644 --- a/web_src/js/index.js +++ b/web_src/js/index.js @@ -352,11 +352,10 @@ function initImagePaste(target) { const field = this; field.addEventListener('paste', (event) => { retrieveImageFromClipboardAsBlob(event, (img) => { - const name = img.name.substr(0, img.name.lastIndexOf('.')); - insertAtCursor(field, `![${name}]()`); + insertAtCursor(field, `![image]()`); uploadFile(img, (res) => { const data = JSON.parse(res); - replaceAndKeepCursor(field, `![${name}]()`, `![${name}](${AppSubUrl}/attachments/${data.uuid})`); + replaceAndKeepCursor(field, `![image]()`, `![image](${AppSubUrl}/attachments/${data.uuid})`); const input = $(``).val(data.uuid); $('.files').append(input); }); @@ -368,11 +367,10 @@ function initImagePaste(target) { function initSimpleMDEImagePaste(simplemde, files) { simplemde.codemirror.on('paste', (_, event) => { retrieveImageFromClipboardAsBlob(event, (img) => { - const name = img.name.substr(0, img.name.lastIndexOf('.')); uploadFile(img, (res) => { const data = JSON.parse(res); const pos = simplemde.codemirror.getCursor(); - simplemde.codemirror.replaceRange(`![${name}](${AppSubUrl}/attachments/${data.uuid})`, pos); + simplemde.codemirror.replaceRange(`![image](${AppSubUrl}/attachments/${data.uuid})`, pos); const input = $(``).val(data.uuid); files.append(input); });