From 70cc3173be245a6812b6be50446451e65d19abd3 Mon Sep 17 00:00:00 2001 From: milotodt Date: Tue, 2 Apr 2019 15:51:37 -0700 Subject: [PATCH 1/4] adjusted handleAttachmentDrop --- .../main/lib/dataApi/attachmentManagement.js | 34 ++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 6fa3b51fa..2c5767350 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -274,11 +274,13 @@ function generateAttachmentMarkdown (fileName, path, showPreview) { * @param {String} noteKey Key of the current note * @param {Event} dropEvent DropEvent */ -function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) { +function handleAttachmentDrop(codeEditor, storageKey, noteKey, dropEvent) { let promise if (dropEvent.dataTransfer.files.length > 0) { promise = Promise.all(Array.from(dropEvent.dataTransfer.files).map(file => { + var filePath = file.path if (file.type.startsWith('image')) { + var a = getOrientation(file) if (file.type === 'image/gif' || file.type === 'image/svg+xml') { return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({ fileName, @@ -286,13 +288,24 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) { isImage: true })) } else { - return fixRotate(file) - .then(data => copyAttachment({type: 'base64', data: data, sourceFilePath: file.path}, storageKey, noteKey) - .then(fileName => ({ + return getOrientation(file) + .then((orientation) => { + if (orientation === -1) { + return copyAttachment(file.path, storageKey, noteKey) + } else { + return fixRotate(file).then(data => copyAttachment({ + type: 'base64', + data: data, + sourceFilePath: filePath + }, storageKey, noteKey)) + } + }) + .then(fileName => + ({ fileName, - title: path.basename(file.path), + title: path.basename(filePath), isImage: true - })) + }) ) } } else { @@ -325,13 +338,18 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) { canvas.height = image.height context.drawImage(image, 0, 0) - return copyAttachment({type: 'base64', data: canvas.toDataURL(), sourceFilePath: imageURL}, storageKey, noteKey) + return copyAttachment({ + type: 'base64', + data: canvas.toDataURL(), + sourceFilePath: imageURL + }, storageKey, noteKey) }) .then(fileName => ({ fileName, title: imageURL, isImage: true - }))]) + })) + ]) } promise.then(files => { From 54dec8a5306e7e1fb89c93cb63869ae18772eacb Mon Sep 17 00:00:00 2001 From: milotodt Date: Tue, 2 Apr 2019 16:04:35 -0700 Subject: [PATCH 2/4] removed uneeded line of code --- browser/main/lib/dataApi/attachmentManagement.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 2c5767350..3cd7a215c 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -274,13 +274,12 @@ function generateAttachmentMarkdown (fileName, path, showPreview) { * @param {String} noteKey Key of the current note * @param {Event} dropEvent DropEvent */ -function handleAttachmentDrop(codeEditor, storageKey, noteKey, dropEvent) { +function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) { let promise if (dropEvent.dataTransfer.files.length > 0) { promise = Promise.all(Array.from(dropEvent.dataTransfer.files).map(file => { var filePath = file.path if (file.type.startsWith('image')) { - var a = getOrientation(file) if (file.type === 'image/gif' || file.type === 'image/svg+xml') { return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({ fileName, @@ -290,7 +289,7 @@ function handleAttachmentDrop(codeEditor, storageKey, noteKey, dropEvent) { } else { return getOrientation(file) .then((orientation) => { - if (orientation === -1) { + if (orientation === -1) { // The image rotation is correct and does not need adjustment return copyAttachment(file.path, storageKey, noteKey) } else { return fixRotate(file).then(data => copyAttachment({ From c5ca88dcf5ec17efbd7fb9749be3f0cae4cc3163 Mon Sep 17 00:00:00 2001 From: milotodt Date: Fri, 5 Apr 2019 14:25:30 -0700 Subject: [PATCH 3/4] Slight refactor --- .../main/lib/dataApi/attachmentManagement.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 3cd7a215c..7f82c5d7b 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -278,19 +278,20 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) { let promise if (dropEvent.dataTransfer.files.length > 0) { promise = Promise.all(Array.from(dropEvent.dataTransfer.files).map(file => { - var filePath = file.path - if (file.type.startsWith('image')) { - if (file.type === 'image/gif' || file.type === 'image/svg+xml') { - return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({ + const filePath = file.path + const fileType = file.type // EX) 'image/gif' or 'text/html' + if (fileType.startsWith('image')) { + if (fileType === 'image/gif' || fileType === 'image/svg+xml') { + return copyAttachment(filePath, storageKey, noteKey).then(fileName => ({ fileName, - title: path.basename(file.path), + title: path.basename(filePath), isImage: true })) } else { return getOrientation(file) .then((orientation) => { if (orientation === -1) { // The image rotation is correct and does not need adjustment - return copyAttachment(file.path, storageKey, noteKey) + return copyAttachment(filePath, storageKey, noteKey) } else { return fixRotate(file).then(data => copyAttachment({ type: 'base64', @@ -308,9 +309,9 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) { ) } } else { - return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({ + return copyAttachment(filePath, storageKey, noteKey).then(fileName => ({ fileName, - title: path.basename(file.path), + title: path.basename(filePath), isImage: false })) } From f13374564c0deb87a2f993be5f34f4935f293f65 Mon Sep 17 00:00:00 2001 From: milotodt Date: Mon, 8 Apr 2019 09:38:31 -0700 Subject: [PATCH 4/4] Repush due to pipeline issues --- browser/main/lib/dataApi/attachmentManagement.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/browser/main/lib/dataApi/attachmentManagement.js b/browser/main/lib/dataApi/attachmentManagement.js index 7f82c5d7b..88c39eb20 100644 --- a/browser/main/lib/dataApi/attachmentManagement.js +++ b/browser/main/lib/dataApi/attachmentManagement.js @@ -85,7 +85,7 @@ function getOrientation (file) { return view.getUint16(offset + (i * 12) + 8, little) } } - } else if ((marker & 0xFF00) !== 0xFF00) { // If not start with 0xFF, not a Marker + } else if ((marker & 0xFF00) !== 0xFF00) { // If not start with 0xFF, not a Marker. break } else { offset += view.getUint16(offset, false)