Skip to content

Commit cef71ef

Browse files
committed
fix: check for node configuration before attempting to register on new node
1 parent 23ef27c commit cef71ef

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/functions/s5.dart

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Future<S5> initS5(
2929
if (!s5.hasIdentity) {
3030
String seed = "";
3131
if (inputSeed != null) {
32+
// first validate the seed
33+
validatePhrase(inputSeed, crypto: s5.api.crypto);
3234
seed = inputSeed;
3335
} else {
3436
seed = s5.generateSeedPhrase();
@@ -45,11 +47,20 @@ Future<S5> initS5(
4547
}
4648
setConfig(DeployConfig(seed: seed, dataKeys: []));
4749
await s5.recoverIdentityFromSeedPhrase(seed);
48-
// if (inputSeed == null) {
49-
await s5.registerOnNewStorageService(
50-
nodeURL,
51-
);
52-
// }
50+
51+
// 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)) {
59+
print("Registering @ $nodeURL");
60+
await s5.registerOnNewStorageService(
61+
nodeURL,
62+
);
63+
}
5364
}
5465
return s5;
5566
}

lib/s5_deploy.dart

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import 'dart:io';
33
import 'package:args/args.dart';
44
import 'package:cli_spin/cli_spin.dart';
55
import 'package:dcli/dcli.dart';
6+
import 'package:lib5/identity.dart';
67
import 'package:lib5/node.dart';
78
import 'package:mime/mime.dart';
89
import 'package:path/path.dart';
@@ -70,8 +71,14 @@ void s5Deploy(List<String> args) async {
7071
// init s5
7172
spinner = spinStart("Initializing S5...");
7273
String nodeURL = results['node'] as String;
73-
final S5 s5 =
74-
await initS5(nodeURL, dbPath, logPath, (results['seed'] as String?));
74+
late S5 s5;
75+
try {
76+
s5 = await initS5(nodeURL, dbPath, logPath, (results['seed'] as String?));
77+
} catch (e) {
78+
spinner.fail();
79+
print(red(e.toString()));
80+
}
81+
7582
spinner.success();
7683

7784
// scan directory

0 commit comments

Comments
 (0)