11import 'package:dcli/dcli.dart' ;
22import 'package:hive/hive.dart' ;
3+ import 'package:http_parser/http_parser.dart' ;
34import 'package:path/path.dart' ;
45import 'package:s5_deploy/definitons/logging.dart' ;
56import 'package:s5/s5.dart' ;
7+ import 'dart:convert' ;
8+ import 'dart:io' ;
9+ import 'package:http/http.dart' as http;
10+ import 'package:s5_deploy/functions/filesystem.dart' ;
611
7- void initS5 (String nodeURL, String dbPath, String logPath) async {
12+ Future < S5 > initS5 (String nodeURL, String dbPath, String logPath) async {
813 final nowInMilliseconds = DateTime .now ().millisecondsSinceEpoch;
914 final lastEightDigits = nowInMilliseconds
1015 .toString ()
1116 .substring (nowInMilliseconds.toString ().length - 8 );
1217 Hive .init (dbPath);
13- final s5 = await S5 .create (
18+ final S5 s5 = await S5 .create (
1419 logger: FileLogger (file: join (logPath, 'log-$lastEightDigits .txt' )));
1520 if (! s5.hasIdentity) {
1621 final seed = s5.generateSeedPhrase ();
@@ -28,4 +33,64 @@ void initS5(String nodeURL, String dbPath, String logPath) async {
2833 nodeURL,
2934 );
3035 }
36+ return s5;
3137}
38+
39+ // Future<CID> uploadDirectory(
40+ // Map<String, Stream<List<int>>> fileStreams,
41+ // Map<String, int> lengths,
42+ // String name, {
43+ // List<String>? tryFiles,
44+ // Map<String, String>? errorPages,
45+ // required Function lookupMimeType,
46+ // }) async {
47+ // final params = {
48+ // 'name': name,
49+ // };
50+
51+ // if (tryFiles != null) {
52+ // params['tryfiles'] = json.encode(tryFiles);
53+ // }
54+ // if (errorPages != null) {
55+ // params['errorpages'] = json.encode(errorPages);
56+ // }
57+
58+ // final uc = storageServiceConfigs.first;
59+
60+ // var uri = uc.getAPIUrl('/s5/upload/directory').replace(
61+ // queryParameters: params,
62+ // );
63+
64+ // var request = http.MultipartRequest("POST", uri);
65+
66+ // request.headers.addAll(uc.headers);
67+
68+ // for (final filename in fileStreams.keys) {
69+ // var stream = http.ByteStream(fileStreams[filename]!);
70+
71+ // final mimeType = lookupMimeType(filename);
72+
73+ // var multipartFile = http.MultipartFile(
74+ // filename,
75+ // stream,
76+ // lengths[filename]!,
77+ // filename: filename,
78+ // contentType: mimeType == null ? null : MediaType.parse(mimeType),
79+ // );
80+
81+ // request.files.add(multipartFile);
82+ // }
83+
84+ // final response = await HttpClient.send(request);
85+
86+ // if (response.statusCode != 200) {
87+ // throw Exception('HTTP ${response.statusCode}');
88+ // }
89+
90+ // final res = await response.stream.transform(utf8.decoder).join();
91+
92+ // final resData = json.decode(res);
93+
94+ // if (resData['cid'] == null) throw Exception('Directory upload failed');
95+ // return CID.decode(resData['cid']);
96+ // }
0 commit comments