Skip to content

Commit 851d3ba

Browse files
committed
fix image path when the dropped image's url contains a query
1 parent 900f20f commit 851d3ba

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

browser/main/lib/dataApi/attachmentManagement.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const mdurl = require('mdurl')
66
const fse = require('fs-extra')
77
const escapeStringRegexp = require('escape-string-regexp')
88
const sander = require('sander')
9+
const url = require('url')
910
import i18n from 'browser/lib/i18n'
1011

1112
const STORAGE_FOLDER_PLACEHOLDER = ':storage'
@@ -159,16 +160,21 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
159160

160161
try {
161162
const isBase64 = typeof sourceFilePath === 'object' && sourceFilePath.type === 'base64'
162-
if (!fs.existsSync(sourceFilePath) && !isBase64) {
163+
if (!isBase64 && !fs.existsSync(sourceFilePath)) {
163164
return reject('source file does not exist')
164165
}
165-
const targetStorage = findStorage.findStorage(storageKey)
166+
167+
const sourcePath = sourceFilePath.sourceFilePath || sourceFilePath
168+
const sourceURL = url.parse(/^\w+:\/\//.test(sourcePath) ? sourcePath : 'file:///' + sourcePath)
169+
166170
let destinationName
167171
if (useRandomName) {
168-
destinationName = `${uniqueSlug()}${path.extname(sourceFilePath.sourceFilePath || sourceFilePath)}`
172+
destinationName = `${uniqueSlug()}${path.extname(sourceURL.pathname) || '.png'}`
169173
} else {
170-
destinationName = path.basename(sourceFilePath.sourceFilePath || sourceFilePath)
174+
destinationName = path.basename(sourceURL.pathname)
171175
}
176+
177+
const targetStorage = findStorage.findStorage(storageKey)
172178
const destinationDir = path.join(targetStorage.path, DESTINATION_FOLDER, noteKey)
173179
createAttachmentDestinationFolder(targetStorage.path, noteKey)
174180
const outputFile = fs.createWriteStream(path.join(destinationDir, destinationName))

0 commit comments

Comments
 (0)