@@ -924,31 +924,42 @@ nav.flex div.overflow-y-auto {
924924 return fetchRsp ;
925925 }
926926 } catch ( e ) { }
927- fetchRsp = target . apply ( thisArg , argumentsList ) ;
928- fetchRsp . then ( response => {
929- let clonedResponse = response . clone ( ) ;
930- clonedResponse . text ( ) . then ( async fetchRspBody => {
931- const fetchRspHeaders = clonedResponse . headers ;
932- if ( fetchReqUrl . match ( '/api/auth/session(\\?|$) ' ) && ! global . st_ec ) {
933- const email = JSON . parse ( fetchRspBody ) . user . email ;
934- global . st_ec = new IndexedDB ( `KeepChatGPT_ ${ email } ` , 'conversations' ) ;
935- cacheEC ( ) ;
936- } else if ( gv ( "k_everchanging" , false ) === true && fetchReqUrl . match ( '/backend-api/conversations\\?.*offset=' ) ) {
937- const b = JSON . parse ( fetchRspBody ) . items ;
938- b . forEach ( async el => {
939- const update_time = new Date ( el . update_time ) ;
940- const ec_tmp = await global . st_ec . get ( el . id ) || { } ;
941- await global . st_ec . put ( { id : el . id , title : el . title , update_time : update_time , last : ec_tmp . last , model : ec_tmp . model } ) ;
942- } ) ;
943- setTimeout ( function ( ) {
927+ let retryCount = 0 ;
928+ const retry = async ( ) => {
929+ fetchRsp = target . apply ( thisArg , argumentsList ) ;
930+ console . log ( 'fetch' , thisArg )
931+ const response = await fetchRsp ;
932+ if ( fetchReqUrl . match ( '/backend- api/conversation$ ' ) && response . status === 429 && retryCount < 20 ) { // solve 429 status_code, retry 20 times
933+ retryCount ++ ;
934+ await new Promise ( resolve => setTimeout ( resolve , 1000 ) ) ; // wait 1 second
935+ return retry ( )
936+ }
937+ fetchRsp . then ( response => {
938+ let clonedResponse = response . clone ( ) ;
939+ clonedResponse . text ( ) . then ( async fetchRspBody => {
940+ const fetchRspHeaders = clonedResponse . headers ;
941+ if ( fetchReqUrl . match ( '/api/auth/session(\\?|$)' ) && ! global . st_ec ) {
942+ const email = JSON . parse ( fetchRspBody ) . user . email ;
943+ global . st_ec = new IndexedDB ( `KeepChatGPT_ ${ email } ` , 'conversations' ) ;
944944 cacheEC ( ) ;
945- attachDate ( ) ;
946- } , 300 ) ;
947- }
948- } ) ;
949- return clonedResponse ;
950- } ) . catch ( error => { } ) ;
951- return fetchRsp ;
945+ } else if ( gv ( "k_everchanging" , false ) === true && fetchReqUrl . match ( '/backend-api/conversations\\?.*offset=' ) ) {
946+ const b = JSON . parse ( fetchRspBody ) . items ;
947+ b . forEach ( async el => {
948+ const update_time = new Date ( el . update_time ) ;
949+ const ec_tmp = await global . st_ec . get ( el . id ) || { } ;
950+ await global . st_ec . put ( { id : el . id , title : el . title , update_time : update_time , last : ec_tmp . last , model : ec_tmp . model } ) ;
951+ } ) ;
952+ setTimeout ( function ( ) {
953+ cacheEC ( ) ;
954+ attachDate ( ) ;
955+ } , 300 ) ;
956+ }
957+ } ) ;
958+ return clonedResponse ;
959+ } ) . catch ( error => { } ) ;
960+ return fetchRsp ;
961+ }
962+ return retry ( )
952963 }
953964 } ) ;
954965 navigator . sendBeacon = function ( url , data ) { } ;
0 commit comments