@@ -38,15 +38,15 @@ export class AutoStorage{
3838 }
3939
4040 async checkAccountSync ( ) {
41- let db = getDatabase ( )
41+ let db = getDatabase ( { snapshot : true } )
4242 if ( this . isAccount ) {
4343 return true
4444 }
4545 if ( localStorage . getItem ( 'dosync' ) === 'avoid' ) {
4646 return false
4747 }
4848 if ( ( localStorage . getItem ( 'dosync' ) === 'sync' || db ?. account ?. useSync ) && ( localStorage . getItem ( 'accountst' ) !== 'able' ) ) {
49- const keys = await this . realStorage . keys ( )
49+ const keys = ( await this . realStorage . keys ( ) ) . filter ( ( key ) => key !== 'database/database.bin' )
5050 let i = 0 ;
5151 const accountStorage = new AccountStorage ( )
5252
@@ -78,26 +78,16 @@ export class AutoStorage{
7878 return false
7979 }
8080
81- let replaced :{ [ key :string ] :string } = { }
82-
83- for ( const key of keys ) {
84- alertStore . set ( {
85- type : "wait" ,
86- msg : `Migrating your data...(${ i } /${ keys . length } )`
87- } )
88- const rkey = await accountStorage . setItem ( key , await this . realStorage . getItem ( key ) )
89- if ( rkey !== key ) {
90- replaced [ key ] = rkey
91- }
92- i += 1
93- }
94-
9581 const {
9682 collectColdStorageBackupPayloads,
9783 setAccountColdStorageItem
9884 } = await import ( "../process/coldstorage.svelte" )
9985 const coldStoragePayloads = await collectColdStorageBackupPayloads ( db )
100- const failedColdKeys :string [ ] = [ ...coldStoragePayloads . missingKeys ]
86+ if ( coldStoragePayloads . missingKeys . length > 0 ) {
87+ alertError ( `Failed to migrate ${ coldStoragePayloads . missingKeys . length } cold storage item(s) to account sync.` )
88+ return false
89+ }
90+ const failedColdKeys :string [ ] = [ ]
10191 for ( let coldIndex = 0 ; coldIndex < coldStoragePayloads . payloads . length ; coldIndex ++ ) {
10292 const payload = coldStoragePayloads . payloads [ coldIndex ]
10393 alertStore . set ( {
@@ -113,6 +103,24 @@ export class AutoStorage{
113103 return false
114104 }
115105
106+ let replaced :{ [ key :string ] :string } = { }
107+ try {
108+ for ( const key of keys ) {
109+ alertStore . set ( {
110+ type : "wait" ,
111+ msg : `Migrating your data...(${ i } /${ keys . length } )`
112+ } )
113+ const rkey = await accountStorage . setItem ( key , await this . realStorage . getItem ( key ) )
114+ if ( rkey !== key ) {
115+ replaced [ key ] = rkey
116+ }
117+ i += 1
118+ }
119+ } catch ( error ) {
120+ alertError ( error )
121+ return false
122+ }
123+
116124 const dba = replaceDbResources ( db , replaced )
117125 const comp = encodeRisuSaveLegacy ( dba , 'compression' )
118126 //try decoding
0 commit comments