@@ -15,22 +15,25 @@ export const COMMON_MIME_TYPES = new Map([
15
15
] ) ;
16
16
17
17
18
- export function toFileWithPath ( file : File , path ?: string ) : FileWithPath {
18
+ export function toFileWithPath ( file : FileWithPath , path ?: string ) : FileWithPath {
19
19
const f = withMimeType ( file ) ;
20
- const { webkitRelativePath} = file as FileWithWebkitPath ;
21
- Object . defineProperty ( f , 'path' , {
22
- value : typeof path === 'string'
23
- ? path
24
- // If <input webkitdirectory> is set,
25
- // the File will have a {webkitRelativePath} property
26
- // https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory
27
- : typeof webkitRelativePath === 'string' && webkitRelativePath . length > 0
28
- ? webkitRelativePath
29
- : file . name ,
30
- writable : false ,
31
- configurable : false ,
32
- enumerable : true
33
- } ) ;
20
+ if ( typeof f . path !== 'string' ) { // on electron, path is already set to the absolute path
21
+ const { webkitRelativePath} = file as FileWithWebkitPath ;
22
+ Object . defineProperty ( f , 'path' , {
23
+ value : typeof path === 'string'
24
+ ? path
25
+ // If <input webkitdirectory> is set,
26
+ // the File will have a {webkitRelativePath} property
27
+ // https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement/webkitdirectory
28
+ : typeof webkitRelativePath === 'string' && webkitRelativePath . length > 0
29
+ ? webkitRelativePath
30
+ : file . name ,
31
+ writable : false ,
32
+ configurable : false ,
33
+ enumerable : true
34
+ } ) ;
35
+ }
36
+
34
37
return f ;
35
38
}
36
39
@@ -42,7 +45,7 @@ interface FileWithWebkitPath extends File {
42
45
readonly webkitRelativePath ?: string ;
43
46
}
44
47
45
- function withMimeType ( file : File ) {
48
+ function withMimeType ( file : FileWithPath ) {
46
49
const { name} = file ;
47
50
const hasExtension = name && name . lastIndexOf ( '.' ) !== - 1 ;
48
51
0 commit comments