@@ -15,6 +15,7 @@ import 'package:s5/s5.dart';
1515import 'dart:convert' ;
1616import 'package:http/http.dart' as http;
1717import 'package:s5_deploy/functions/config.dart' ;
18+ import 'package:s5_deploy/functions/spinner.dart' ;
1819import 'package:xdg_directories/xdg_directories.dart' ;
1920
2021Future <S5 > initS5 (
@@ -48,14 +49,19 @@ Future<S5> initS5(
4849 setConfig (DeployConfig (seed: seed, dataKeys: []));
4950 await s5.recoverIdentityFromSeedPhrase (seed);
5051
52+ // now check if already registered on node
53+ List <String >? urls;
5154 // then check if already registered
52- Map <dynamic , dynamic > data = (s5.api as S5NodeAPIWithIdentity ).accounts;
53- final Map <String , dynamic > accounts =
54- data['accounts' ] as Map <String , dynamic >;
55- final List <String > urls =
56- accounts.values.map ((account) => account['url' ] as String ).toList ();
57- // And if the nodeURL isn't on the seed already, authenticate on that server
58- if (! urls.contains (nodeURL)) {
55+ if ((s5.api as S5NodeAPIWithIdentity ).accounts.isNotEmpty) {
56+ Map <dynamic , dynamic > data = (s5.api as S5NodeAPIWithIdentity ).accounts;
57+ final Map <String , dynamic > accounts = (data['accounts' ] as Map ).map (
58+ (key, value) => MapEntry (key as String , value),
59+ );
60+ urls =
61+ accounts.values.map ((account) => account['url' ] as String ).toList ();
62+ // And if the nodeURL isn't on the seed already, authenticate on that server
63+ }
64+ if (urls == null || ! urls.contains (nodeURL)) {
5965 print ("Registering @ $nodeURL " );
6066 await s5.registerOnNewStorageService (
6167 nodeURL,
@@ -136,28 +142,27 @@ Future<CID> updateResolver(
136142 setConfig (conf);
137143 }
138144
145+ // Then we get get an set the resolver
139146 final resolverSeed = s5.api.crypto.hashBlake3Sync (
140147 Uint8List .fromList (
141- validatePhrase (seed, crypto: s5.api.crypto) + utf8.encode (dataKey),
148+ validatePhrase (seed, crypto: s5.api.crypto) +
149+ utf8.encode (dataKey), // this identifies the backup
142150 ),
143151 );
144152
145153 final s5User = await s5.api.crypto.newKeyPairEd25519 (seed: resolverSeed);
146154
147155 SignedRegistryEntry ? existing;
156+ int revision = 0 ;
148157
149158 try {
150159 final res = await s5.api.registryGet (s5User.publicKey);
151160 existing = res;
152- if (existing != null ) {
153- print (
154- 'Revision ${existing .revision } -> ${existing .revision + 1 }' ,
155- );
156- }
161+ revision = existing! .revision + 1 ;
157162 } catch (e) {
158163 existing = null ;
159164
160- print ( 'Revision 1' ) ;
165+ revision = 1 ;
161166 }
162167
163168 final sre = await signRegistryEntry (
@@ -176,6 +181,13 @@ Future<CID> updateResolver(
176181 s5User.publicKey,
177182 ),
178183 ));
184+
185+ if (resolverCID.hash.toBase64Url () != "" ) {
186+ spinner.success ();
187+ spinner = spinStart ("Updating to revision $revision " );
188+ spinner.success ();
189+ }
190+
179191 return resolverCID;
180192 } else {
181193 spinner.fail ();
0 commit comments