mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
adjusted handleAttachmentDrop
This commit is contained in:
@@ -274,11 +274,13 @@ function generateAttachmentMarkdown (fileName, path, showPreview) {
|
|||||||
* @param {String} noteKey Key of the current note
|
* @param {String} noteKey Key of the current note
|
||||||
* @param {Event} dropEvent DropEvent
|
* @param {Event} dropEvent DropEvent
|
||||||
*/
|
*/
|
||||||
function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
function handleAttachmentDrop(codeEditor, storageKey, noteKey, dropEvent) {
|
||||||
let promise
|
let promise
|
||||||
if (dropEvent.dataTransfer.files.length > 0) {
|
if (dropEvent.dataTransfer.files.length > 0) {
|
||||||
promise = Promise.all(Array.from(dropEvent.dataTransfer.files).map(file => {
|
promise = Promise.all(Array.from(dropEvent.dataTransfer.files).map(file => {
|
||||||
|
var filePath = file.path
|
||||||
if (file.type.startsWith('image')) {
|
if (file.type.startsWith('image')) {
|
||||||
|
var a = getOrientation(file)
|
||||||
if (file.type === 'image/gif' || file.type === 'image/svg+xml') {
|
if (file.type === 'image/gif' || file.type === 'image/svg+xml') {
|
||||||
return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({
|
return copyAttachment(file.path, storageKey, noteKey).then(fileName => ({
|
||||||
fileName,
|
fileName,
|
||||||
@@ -286,13 +288,24 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
|||||||
isImage: true
|
isImage: true
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
return fixRotate(file)
|
return getOrientation(file)
|
||||||
.then(data => copyAttachment({type: 'base64', data: data, sourceFilePath: file.path}, storageKey, noteKey)
|
.then((orientation) => {
|
||||||
.then(fileName => ({
|
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,
|
fileName,
|
||||||
title: path.basename(file.path),
|
title: path.basename(filePath),
|
||||||
isImage: true
|
isImage: true
|
||||||
}))
|
})
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -325,13 +338,18 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
|||||||
canvas.height = image.height
|
canvas.height = image.height
|
||||||
context.drawImage(image, 0, 0)
|
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 => ({
|
.then(fileName => ({
|
||||||
fileName,
|
fileName,
|
||||||
title: imageURL,
|
title: imageURL,
|
||||||
isImage: true
|
isImage: true
|
||||||
}))])
|
}))
|
||||||
|
])
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then(files => {
|
promise.then(files => {
|
||||||
|
|||||||
Reference in New Issue
Block a user