mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-14 02:06:29 +00:00
fix dropping image from Firefox on Linux
This commit is contained in:
@@ -304,32 +304,34 @@ function handleAttachmentDrop (codeEditor, storageKey, noteKey, dropEvent) {
|
|||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
promise = Promise.all(Array.from(dropEvent.dataTransfer.items).map(item => {
|
let imageURL = dropEvent.dataTransfer.getData('text/plain')
|
||||||
if (item.type === 'text/html') {
|
|
||||||
const html = dropEvent.dataTransfer.getData('text/html')
|
|
||||||
|
|
||||||
const match = /<img[^>]*[\s"']src="([^"]+)"/.exec(html)
|
if (!imageURL) {
|
||||||
if (match) {
|
const match = /<img[^>]*[\s"']src="([^"]+)"/.exec(dropEvent.dataTransfer.getData('text/html'))
|
||||||
const imageURL = match[1]
|
if (match) {
|
||||||
|
imageURL = match[1]
|
||||||
return getImage(imageURL)
|
|
||||||
.then(image => {
|
|
||||||
const canvas = document.createElement('canvas')
|
|
||||||
const context = canvas.getContext('2d')
|
|
||||||
canvas.width = image.width
|
|
||||||
canvas.height = image.height
|
|
||||||
context.drawImage(image, 0, 0)
|
|
||||||
|
|
||||||
return copyAttachment({type: 'base64', data: canvas.toDataURL(), sourceFilePath: imageURL}, storageKey, noteKey)
|
|
||||||
})
|
|
||||||
.then(fileName => ({
|
|
||||||
fileName,
|
|
||||||
title: imageURL,
|
|
||||||
isImage: true
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}))
|
}
|
||||||
|
|
||||||
|
if (!imageURL) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
promise = Promise.all([getImage(imageURL)
|
||||||
|
.then(image => {
|
||||||
|
const canvas = document.createElement('canvas')
|
||||||
|
const context = canvas.getContext('2d')
|
||||||
|
canvas.width = image.width
|
||||||
|
canvas.height = image.height
|
||||||
|
context.drawImage(image, 0, 0)
|
||||||
|
|
||||||
|
return copyAttachment({type: 'base64', data: canvas.toDataURL(), sourceFilePath: imageURL}, storageKey, noteKey)
|
||||||
|
})
|
||||||
|
.then(fileName => ({
|
||||||
|
fileName,
|
||||||
|
title: imageURL,
|
||||||
|
isImage: true
|
||||||
|
}))])
|
||||||
}
|
}
|
||||||
|
|
||||||
promise.then(files => {
|
promise.then(files => {
|
||||||
|
|||||||
Reference in New Issue
Block a user