@@ -19,30 +19,30 @@ export default class OneDriveFileSystem implements FileSystem {
1919 return this . list ( ) . then ( ) ;
2020 }
2121
22- open ( file : File ) : Promise < FileReader > {
23- return Promise . resolve ( new OneDriveFileReader ( this , file ) ) ;
22+ async open ( file : File ) : Promise < FileReader > {
23+ return new OneDriveFileReader ( this , file ) ;
2424 }
2525
26- openDir ( path : string ) : Promise < FileSystem > {
26+ async openDir ( path : string ) : Promise < FileSystem > {
2727 if ( path . startsWith ( "ScriptCat" ) ) {
2828 path = path . substring ( 9 ) ;
2929 }
30- return Promise . resolve ( new OneDriveFileSystem ( joinPath ( this . path , path ) , this . accessToken ) ) ;
30+ return new OneDriveFileSystem ( joinPath ( this . path , path ) , this . accessToken ) ;
3131 }
3232
33- create ( path : string ) : Promise < FileWriter > {
34- return Promise . resolve ( new OneDriveFileWriter ( this , joinPath ( this . path , path ) ) ) ;
33+ async create ( path : string ) : Promise < FileWriter > {
34+ return new OneDriveFileWriter ( this , joinPath ( this . path , path ) ) ;
3535 }
3636
37- createDir ( dir : string ) : Promise < void > {
37+ async createDir ( dir : string ) : Promise < void > {
3838 if ( dir && dir . startsWith ( "ScriptCat" ) ) {
3939 dir = dir . substring ( 9 ) ;
4040 if ( dir . startsWith ( "/" ) ) {
4141 dir = dir . substring ( 1 ) ;
4242 }
4343 }
4444 if ( ! dir ) {
45- return Promise . resolve ( ) ;
45+ return ;
4646 }
4747 dir = joinPath ( this . path , dir ) ;
4848 const dirs = dir . split ( "/" ) ;
@@ -55,23 +55,21 @@ export default class OneDriveFileSystem implements FileSystem {
5555 if ( parent !== "" ) {
5656 parent = `:${ parent } :` ;
5757 }
58- return this . request ( `https://graph.microsoft.com/v1.0/me/drive/special/approot${ parent } /children` , {
58+ const data = await this . request ( `https://graph.microsoft.com/v1.0/me/drive/special/approot${ parent } /children` , {
5959 method : "POST" ,
6060 headers : myHeaders ,
6161 body : JSON . stringify ( {
6262 name : dirs [ dirs . length - 1 ] ,
6363 folder : { } ,
6464 "@microsoft.graph.conflictBehavior" : "replace" ,
6565 } ) ,
66- } ) . then ( ( data : any ) => {
67- if ( data . errno ) {
68- throw new Error ( JSON . stringify ( data ) ) ;
69- }
70- return Promise . resolve ( ) ;
7166 } ) ;
67+ if ( data . errno ) {
68+ throw new Error ( JSON . stringify ( data ) ) ;
69+ }
7270 }
7371
74- request ( url : string , config ?: RequestInit , nothen ?: boolean ) {
72+ request ( url : string , config ?: RequestInit , nothen ?: boolean ) : Promise < Response | any > {
7573 config = config || { } ;
7674 const headers = < Headers > config . headers || new Headers ( ) ;
7775 if ( url . indexOf ( "uploadSession" ) === - 1 ) {
@@ -105,42 +103,39 @@ export default class OneDriveFileSystem implements FileSystem {
105103 } ) ;
106104 }
107105
108- delete ( path : string ) : Promise < void > {
109- return this . request (
106+ async delete ( path : string ) : Promise < void > {
107+ const resp = await this . request (
110108 `https://graph.microsoft.com/v1.0/me/drive/special/approot:${ joinPath ( this . path , path ) } ` ,
111109 {
112110 method : "DELETE" ,
113111 } ,
114112 true
115- ) . then ( async ( resp ) => {
116- if ( resp . status !== 204 ) {
117- throw new Error ( await resp . text ( ) ) ;
118- }
119- return resp ;
120- } ) ;
113+ ) ;
114+ if ( resp . status !== 204 ) {
115+ throw new Error ( await resp . text ( ) ) ;
116+ }
117+ return resp ;
121118 }
122119
123- list ( ) : Promise < File [ ] > {
120+ async list ( ) : Promise < File [ ] > {
124121 let { path } = this ;
125122 if ( path === "/" ) {
126123 path = "" ;
127124 } else {
128125 path = `:${ path } :` ;
129126 }
130- return this . request ( `https://graph.microsoft.com/v1.0/me/drive/special/approot${ path } /children` ) . then ( ( data ) => {
131- const list : File [ ] = [ ] ;
132- data . value . forEach ( ( val : any ) => {
133- list . push ( {
134- name : val . name ,
135- path : this . path ,
136- size : val . size ,
137- digest : val . eTag ,
138- createtime : new Date ( val . createdDateTime ) . getTime ( ) ,
139- updatetime : new Date ( val . lastModifiedDateTime ) . getTime ( ) ,
140- } ) ;
127+ const data = await this . request ( `https://graph.microsoft.com/v1.0/me/drive/special/approot${ path } /children` ) ;
128+ const list : File [ ] = data . value . map ( ( val : any ) => {
129+ return ( {
130+ name : val . name ,
131+ path : this . path ,
132+ size : val . size ,
133+ digest : val . eTag ,
134+ createtime : new Date ( val . createdDateTime ) . getTime ( ) ,
135+ updatetime : new Date ( val . lastModifiedDateTime ) . getTime ( ) ,
141136 } ) ;
142- return list ;
143137 } ) ;
138+ return list ;
144139 }
145140
146141 getDirUrl ( ) : Promise < string > {
0 commit comments