mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 17:56:25 +00:00
fix image path when the dropped image's url contains a query
This commit is contained in:
@@ -6,6 +6,7 @@ const mdurl = require('mdurl')
|
|||||||
const fse = require('fs-extra')
|
const fse = require('fs-extra')
|
||||||
const escapeStringRegexp = require('escape-string-regexp')
|
const escapeStringRegexp = require('escape-string-regexp')
|
||||||
const sander = require('sander')
|
const sander = require('sander')
|
||||||
|
const url = require('url')
|
||||||
import i18n from 'browser/lib/i18n'
|
import i18n from 'browser/lib/i18n'
|
||||||
|
|
||||||
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
|
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
|
||||||
@@ -159,16 +160,21 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const isBase64 = typeof sourceFilePath === 'object' && sourceFilePath.type === 'base64'
|
const isBase64 = typeof sourceFilePath === 'object' && sourceFilePath.type === 'base64'
|
||||||
if (!fs.existsSync(sourceFilePath) && !isBase64) {
|
if (!isBase64 && !fs.existsSync(sourceFilePath)) {
|
||||||
return reject('source file does not exist')
|
return reject('source file does not exist')
|
||||||
}
|
}
|
||||||
const targetStorage = findStorage.findStorage(storageKey)
|
|
||||||
|
const sourcePath = sourceFilePath.sourceFilePath || sourceFilePath
|
||||||
|
const sourceURL = url.parse(/^\w+:\/\//.test(sourcePath) ? sourcePath : 'file:///' + sourcePath)
|
||||||
|
|
||||||
let destinationName
|
let destinationName
|
||||||
if (useRandomName) {
|
if (useRandomName) {
|
||||||
destinationName = `${uniqueSlug()}${path.extname(sourceFilePath.sourceFilePath || sourceFilePath)}`
|
destinationName = `${uniqueSlug()}${path.extname(sourceURL.pathname) || '.png'}`
|
||||||
} else {
|
} else {
|
||||||
destinationName = path.basename(sourceFilePath.sourceFilePath || sourceFilePath)
|
destinationName = path.basename(sourceURL.pathname)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const targetStorage = findStorage.findStorage(storageKey)
|
||||||
const destinationDir = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
const destinationDir = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
|
||||||
createAttachmentDestinationFolder(targetStorage.path, noteKey)
|
createAttachmentDestinationFolder(targetStorage.path, noteKey)
|
||||||
const outputFile = fs.createWriteStream(path.join(destinationDir, destinationName))
|
const outputFile = fs.createWriteStream(path.join(destinationDir, destinationName))
|
||||||
|
|||||||
Reference in New Issue
Block a user