@@ -39,7 +39,7 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
39
39
40
40
const targetStorage = findStorage . findStorage ( storageKey )
41
41
42
- const inputFile = fs . createReadStream ( sourceFilePath )
42
+ const inputFileStream = fs . createReadStream ( sourceFilePath )
43
43
let destinationName
44
44
if ( useRandomName ) {
45
45
destinationName = `${ uniqueSlug ( ) } ${ path . extname ( sourceFilePath ) } `
@@ -49,8 +49,10 @@ function copyAttachment (sourceFilePath, storageKey, noteKey, useRandomName = tr
49
49
const destinationDir = path . join ( targetStorage . path , DESTINATION_FOLDER , noteKey )
50
50
createAttachmentDestinationFolder ( targetStorage . path , noteKey )
51
51
const outputFile = fs . createWriteStream ( path . join ( destinationDir , destinationName ) )
52
- inputFile . pipe ( outputFile )
53
- resolve ( destinationName )
52
+ inputFileStream . pipe ( outputFile )
53
+ inputFileStream . on ( 'end' , ( ) => {
54
+ resolve ( destinationName )
55
+ } )
54
56
} catch ( e ) {
55
57
return reject ( e )
56
58
}
@@ -146,7 +148,7 @@ function handlePastImageEvent (codeEditor, storageKey, noteKey, dataTransferItem
146
148
base64data = reader . result . replace ( / ^ d a t a : i m a g e \/ p n g ; b a s e 6 4 , / , '' )
147
149
base64data += base64data . replace ( '+' , ' ' )
148
150
const binaryData = new Buffer ( base64data , 'base64' ) . toString ( 'binary' )
149
- fs . writeFile ( imagePath , binaryData , 'binary' )
151
+ fs . writeFileSync ( imagePath , binaryData , 'binary' )
150
152
let imageMd = generateAttachmentMarkdown ( imageName , imagePath , true )
151
153
codeEditor . insertAttachmentMd ( imageMd )
152
154
}
0 commit comments