@@ -27,7 +27,7 @@ const getCurrentPlatform = (): string => {
27
27
// Thanks to vs-picgo: https://github.com/Spades-S/vs-picgo/blob/master/src/extension.ts
28
28
const getClipboardImage = async ( ctx : IPicGo ) : Promise < IClipboardImage > => {
29
29
const imagePath = path . join ( ctx . baseDir , `${ dayjs ( ) . format ( 'YYYYMMDDHHmmss' ) } .png` )
30
- return await new Promise < IClipboardImage > ( ( resolve : Function ) : void => {
30
+ return await new Promise < IClipboardImage > ( ( resolve : Function , reject : Function ) : void => {
31
31
const platform : string = getCurrentPlatform ( )
32
32
let execution
33
33
// for PicGo GUI
@@ -65,23 +65,35 @@ const getClipboardImage = async (ctx: IPicGo): Promise<IClipboardImage> => {
65
65
execution . stdout . on ( 'data' , ( data : Buffer ) => {
66
66
if ( platform === 'linux' ) {
67
67
if ( data . toString ( ) . trim ( ) === 'no xclip' ) {
68
- return ctx . emit ( IBuildInEvent . NOTIFICATION , {
68
+ ctx . emit ( IBuildInEvent . NOTIFICATION , {
69
69
title : 'xclip not found' ,
70
70
body : 'Please install xclip before run picgo'
71
71
} )
72
+ return reject ( new Error ( 'Please install xclip before run picgo' ) )
72
73
}
73
74
}
74
75
const imgPath = data . toString ( ) . trim ( )
75
- let isExistFile = false
76
+
77
+ // if the filePath is the real file in system
78
+ // we should keep it instead of removing
79
+ let shouldKeepAfterUploading = false
80
+
76
81
// in macOS if your copy the file in system, it's basename will not equal to our default basename
77
82
if ( path . basename ( imgPath ) !== path . basename ( imagePath ) ) {
83
+ // if the path is not generate by picgo
84
+ // but the path exists, we should keep it
78
85
if ( fs . existsSync ( imgPath ) ) {
79
- isExistFile = true
86
+ shouldKeepAfterUploading = true
80
87
}
81
88
}
89
+ // if the imgPath is invalid
90
+ if ( ! fs . existsSync ( imgPath ) ) {
91
+ return reject ( new Error ( `Can't find ${ imgPath } ` ) )
92
+ }
93
+
82
94
resolve ( {
83
95
imgPath,
84
- isExistFile
96
+ shouldKeepAfterUploading
85
97
} )
86
98
} )
87
99
} )
0 commit comments