@@ -42,7 +42,7 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
42
42
43
43
const targetStorage = findStorage . findStorage ( storageKey )
44
44
45
- const inputFile = fs . createReadStream ( sourceFilePath )
45
+ const inputFileStream = fs . createReadStream ( sourceFilePath )
46
46
let destinationName
47
47
if ( useRandomName ) {
48
48
destinationName = `${ uniqueSlug ( ) } ${ path . extname ( sourceFilePath ) } `
@@ -52,8 +52,10 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
52
52
const destinationDir = path . join ( targetStorage . path , DESTINATION_FOLDER , noteKey )
53
53
createAttachmentDestinationFolder ( targetStorage . path , noteKey )
54
54
const outputFile = fs . createWriteStream ( path . join ( destinationDir , destinationName ) )
55
- inputFile . pipe ( outputFile )
56
- resolve ( destinationName )
55
+ inputFileStream . pipe ( outputFile )
56
+ inputFileStream . on ( 'end' , ( ) => {
57
+ resolve ( destinationName )
58
+ } )
57
59
} catch ( e ) {
58
60
return reject ( e )
59
61
}
@@ -149,7 +151,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem
149
151
base64data = reader . result . replace ( / ^ d a t a : i m a g e \/ p n g ; b a s e 6 4 , / , '' )
150
152
base64data += base64data . replace ( '+' , ' ' )
151
153
const binaryData = new Buffer ( base64data , 'base64' ) . toString ( 'binary' )
152
- fs . writeFile ( imagePath , binaryData , 'binary' )
154
+ fs . writeFileSync ( imagePath , binaryData , 'binary' )
153
155
const imageMd = generateAttachmentMarkdown ( imageName , imagePath , true )
154
156
codeEditor . insertAttachmentMd ( imageMd )
155
157
}
@@ -174,7 +176,7 @@ function getAttachmentsInContent (markdownContent) {
174
176
* @returns {String[] } Absolute paths of the referenced attachments
175
177
*/
176
178
function getAbsolutePathsOfAttachmentsInContent ( markdownContent , storagePath ) {
177
- const temp = getAttachmentsInContent ( markdownContent )
179
+ const temp = getAttachmentsInContent ( markdownContent ) || [ ]
178
180
const result = [ ]
179
181
for ( const relativePath of temp ) {
180
182
result . push ( relativePath . replace ( new RegExp ( STORAGE_FOLDER_PLACEHOLDER , 'g' ) , path . join ( storagePath , DESTINATION_FOLDER ) ) )
0 commit comments