@@ -9,6 +9,7 @@ const isShadowRocket = 'undefined' !== typeof $rocket;
99const isEgern = 'object' == typeof egern ;
1010const isLanceX = 'undefined' != typeof $native ;
1111const isGUIforCores = typeof $Plugins !== 'undefined' ;
12+ import { Base64 } from 'js-base64' ;
1213
1314function isPlainObject ( obj ) {
1415 return (
@@ -120,13 +121,27 @@ export class OpenAPI {
120121 if ( this . node . fs . existsSync ( fpath ) ) {
121122 try {
122123 this . cache = JSON . parse (
123- this . node . fs . readFileSync ( `${ fpath } ` ) ,
124+ this . node . fs . readFileSync ( `${ fpath } ` , 'utf-8' ) ,
124125 ) ;
126+ if ( ! isPlainObject ( this . cache ) )
127+ throw new Error ( 'Invalid Data' ) ;
125128 } catch ( e ) {
126- this . node . fs . copyFileSync ( fpath , backupPath ) ;
127- this . error (
128- `Failed to parse ${ fpath } : ${ e . message } . Backup created at ${ backupPath } ` ,
129- ) ;
129+ try {
130+ const str = Base64 . decode (
131+ this . node . fs . readFileSync ( `${ fpath } ` , 'utf-8' ) ,
132+ ) ;
133+ this . cache = JSON . parse ( str ) ;
134+ this . node . fs . writeFileSync ( fpath , str , {
135+ flag : 'w' ,
136+ } ) ;
137+ if ( ! isPlainObject ( this . cache ) )
138+ throw new Error ( 'Invalid Data' ) ;
139+ } catch ( e ) {
140+ this . node . fs . copyFileSync ( fpath , backupPath ) ;
141+ this . error (
142+ `Failed to parse ${ fpath } : ${ e . message } . Backup created at ${ backupPath } ` ,
143+ ) ;
144+ }
130145 }
131146 }
132147 if ( ! isPlainObject ( this . cache ) ) {
0 commit comments