@@ -5,17 +5,24 @@ import { WebDAVFileReader, WebDAVFileWriter } from "./rw";
5
5
export default class WebDAVFileSystem implements FileSystem {
6
6
client : WebDAVClient ;
7
7
8
+ basePath : string = "" ;
9
+
8
10
constructor (
9
- authType : AuthType ,
10
- url : string ,
11
- username : string ,
12
- password : string
11
+ authType : AuthType | WebDAVClient ,
12
+ url ? : string ,
13
+ username ? : string ,
14
+ password ? : string
13
15
) {
14
- this . client = createClient ( url , {
15
- authType,
16
- username,
17
- password,
18
- } ) ;
16
+ if ( typeof authType === "object" ) {
17
+ this . client = authType ;
18
+ this . basePath = url || "" ;
19
+ } else {
20
+ this . client = createClient ( url ! , {
21
+ authType,
22
+ username,
23
+ password,
24
+ } ) ;
25
+ }
19
26
}
20
27
21
28
async verify ( ) : Promise < void > {
@@ -24,20 +31,39 @@ export default class WebDAVFileSystem implements FileSystem {
24
31
}
25
32
26
33
open ( path : string ) : Promise < FileReader > {
27
- return Promise . resolve ( new WebDAVFileReader ( this . client , path ) ) ;
34
+ return Promise . resolve (
35
+ new WebDAVFileReader ( this . client , this . getPath ( path ) )
36
+ ) ;
37
+ }
38
+
39
+ openDir ( path : string ) : Promise < FileSystem > {
40
+ if ( ! path . endsWith ( "/" ) ) {
41
+ path += "/" ;
42
+ }
43
+ return Promise . resolve ( new WebDAVFileSystem ( this . client , path ) ) ;
28
44
}
29
45
30
46
create ( path : string ) : Promise < FileWriter > {
31
- return Promise . resolve ( new WebDAVFileWriter ( this . client , path ) ) ;
47
+ return Promise . resolve (
48
+ new WebDAVFileWriter ( this . client , this . getPath ( path ) )
49
+ ) ;
50
+ }
51
+
52
+ createDir ( path : string ) : Promise < void > {
53
+ return this . client . createDirectory ( this . getPath ( path ) ) ;
32
54
}
33
55
34
56
async delete ( path : string ) : Promise < void > {
35
- return this . client . deleteFile ( path ) ;
57
+ return this . client . deleteFile ( this . getPath ( path ) ) ;
58
+ }
59
+
60
+ getPath ( path : string ) : string {
61
+ return this . basePath + path ;
36
62
}
37
63
38
64
async list ( path ?: string | undefined ) : Promise < File [ ] > {
39
65
const dir = ( await this . client . getDirectoryContents (
40
- path || ""
66
+ this . getPath ( path || "" )
41
67
) ) as FileStat [ ] ;
42
68
const ret : File [ ] = [ ] ;
43
69
dir . forEach ( ( item : FileStat ) => {
0 commit comments