@@ -22,7 +22,7 @@ export default class OneDriveFileSystem implements FileSystem {
2222 async verify ( ) : Promise < void > {
2323 const token = await AuthVerify ( "onedrive" ) ;
2424 this . accessToken = token ;
25- return Promise . resolve ( ) ;
25+ return this . list ( ) . then ( ) ;
2626 }
2727
2828 open ( file : File ) : Promise < FileReader > {
@@ -73,7 +73,7 @@ export default class OneDriveFileSystem implements FileSystem {
7373 "@microsoft.graph.conflictBehavior" : "replace" ,
7474 } ) ,
7575 }
76- ) . then ( ( data ) => {
76+ ) . then ( ( data : any ) => {
7777 if ( data . errno ) {
7878 throw new Error ( JSON . stringify ( data ) ) ;
7979 }
@@ -85,7 +85,6 @@ export default class OneDriveFileSystem implements FileSystem {
8585 request ( url : string , config ?: RequestInit , nothen ?: boolean ) {
8686 config = config || { } ;
8787 const headers = < Headers > config . headers || new Headers ( ) ;
88- // 利用GM函数的匿名实现不发送cookie,因为某些情况cookie会导致-6错误
8988 headers . append ( `Authorization` , `Bearer ${ this . accessToken } ` ) ;
9089 config . headers = headers ;
9190 const ret = fetch ( url , config ) ;
@@ -96,6 +95,19 @@ export default class OneDriveFileSystem implements FileSystem {
9695 . then ( ( data ) => data . json ( ) )
9796 . then ( async ( data ) => {
9897 if ( data . error ) {
98+ if ( data . error . code === "InvalidAuthenticationToken" ) {
99+ const token = await AuthVerify ( "onedrive" , true ) ;
100+ this . accessToken = token ;
101+ headers . set ( `Authorization` , `Bearer ${ this . accessToken } ` ) ;
102+ return fetch ( url , config )
103+ . then ( ( retryData ) => retryData . json ( ) )
104+ . then ( ( retryData ) => {
105+ if ( retryData . error ) {
106+ throw new Error ( JSON . stringify ( retryData ) ) ;
107+ }
108+ return data ;
109+ } ) ;
110+ }
99111 throw new Error ( JSON . stringify ( data ) ) ;
100112 }
101113 return data ;
@@ -128,6 +140,7 @@ export default class OneDriveFileSystem implements FileSystem {
128140 return this . request (
129141 `https://graph.microsoft.com/v1.0/me/drive/special/approot:${ path } :/children`
130142 ) . then ( ( data ) => {
143+ console . log ( data ) ;
131144 const list : File [ ] = [ ] ;
132145 data . value . forEach ( ( val : any ) => {
133146 list . push ( {
0 commit comments