mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
Merge pull request #1824 from ZeroX-DG/fix-paste-image
Fixed image not displaying after paste
This commit is contained in:
@@ -331,9 +331,14 @@ export default class CodeEditor extends React.Component {
|
|||||||
const imageDir = path.join(storagePath, 'images')
|
const imageDir = path.join(storagePath, 'images')
|
||||||
if (!fs.existsSync(imageDir)) fs.mkdirSync(imageDir)
|
if (!fs.existsSync(imageDir)) fs.mkdirSync(imageDir)
|
||||||
const imagePath = path.join(imageDir, `${imageName}.png`)
|
const imagePath = path.join(imageDir, `${imageName}.png`)
|
||||||
fs.writeFile(imagePath, binaryData, 'binary')
|
fs.writeFile(imagePath, binaryData, 'binary', (error) => {
|
||||||
const imageMd = `})`
|
if (error) {
|
||||||
this.insertImageMd(imageMd)
|
throw error
|
||||||
|
} else {
|
||||||
|
const imageMd = `})`
|
||||||
|
this.insertImageMd(imageMd)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
} else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) {
|
} else if (this.props.fetchUrlTitle && isURL(pastedTxt) && !isInLinkTag(editor)) {
|
||||||
this.handlePasteUrl(e, editor, pastedTxt)
|
this.handlePasteUrl(e, editor, pastedTxt)
|
||||||
|
|||||||
@@ -21,8 +21,12 @@ function copyImage (filePath, storageKey, rename = true) {
|
|||||||
const imageDir = path.join(targetStorage.path, 'images')
|
const imageDir = path.join(targetStorage.path, 'images')
|
||||||
if (!fs.existsSync(imageDir)) fs.mkdirSync(imageDir)
|
if (!fs.existsSync(imageDir)) fs.mkdirSync(imageDir)
|
||||||
const outputImage = fs.createWriteStream(path.join(imageDir, basename))
|
const outputImage = fs.createWriteStream(path.join(imageDir, basename))
|
||||||
|
outputImage.on('error', reject)
|
||||||
|
inputImage.on('error', reject)
|
||||||
|
inputImage.on('end', () => {
|
||||||
|
resolve(basename)
|
||||||
|
})
|
||||||
inputImage.pipe(outputImage)
|
inputImage.pipe(outputImage)
|
||||||
resolve(basename)
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return reject(e)
|
return reject(e)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user