Skip to content

Commit ce442be

Browse files
committed
Improve FileSystemProvider and fix s3 endpoint url handling
1 parent e0d48da commit ce442be

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

lib/store/create.dart

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ Map<String, ObjectStore> createStoresFromConfig(
3131
final stores = <String, ObjectStore>{};
3232

3333
if (s3Config != null) {
34+
final String endpointUrl = s3Config['endpointUrl'] ?? s3Config['endpoint'];
35+
final uri = Uri.tryParse(endpointUrl);
3436
stores['s3'] = S3ObjectStore(
3537
Minio(
36-
endPoint: s3Config['endpoint'],
38+
useSSL: (uri?.scheme ?? 'https') == 'https',
39+
endPoint: uri?.host ?? endpointUrl,
40+
port: uri?.port,
3741
accessKey: s3Config['accessKey'],
3842
secretKey: s3Config['secretKey'],
3943
),
@@ -99,10 +103,16 @@ Map<String, ObjectStore> createStoresFromConfig(
99103
} */
100104

101105
if (fileSystemConfig != null) {
102-
stores['fs'] = FileSystemProviderObjectStore(node, localDirectories: [
103-
// TODO Configure directories
104-
Directory('/public'),
105-
]);
106+
stores['fs'] = FileSystemProviderObjectStore(
107+
node,
108+
localDirectories: [
109+
for (final path in fileSystemConfig['directories']) Directory(path),
110+
],
111+
httpPort: fileSystemConfig['httpPort'] ?? 23432,
112+
httpBind: fileSystemConfig['httpBind'] ?? '0.0.0.0',
113+
externalDownloadUrl:
114+
fileSystemConfig['externalDownloadUrl'] ?? 'http://localhost:23432',
115+
);
106116
}
107117

108118
if (siaConfig != null) {

lib/store/fs_provider.dart

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,18 @@ class FileSystemProviderObjectStore extends ObjectStore {
171171
@override
172172
final uploadsSupported = false;
173173

174-
// TODO Make port configurable
175-
final httpServerConfig = {
176-
'port': 23432,
177-
};
178-
179-
FileSystemProviderObjectStore(this.node, {required this.localDirectories}) {
174+
final String externalDownloadUrl;
175+
176+
final int httpPort;
177+
final String httpBind;
178+
179+
FileSystemProviderObjectStore(
180+
this.node, {
181+
required this.localDirectories,
182+
required this.httpPort,
183+
required this.httpBind,
184+
required this.externalDownloadUrl,
185+
}) {
180186
final app = Alfred();
181187

182188
app.all('*', cors());
@@ -186,11 +192,13 @@ class FileSystemProviderObjectStore extends ObjectStore {
186192
if (metadataHashes.containsKey(hash)) {
187193
res.add(metadataHashes[hash]!);
188194
res.close();
195+
} else if (fileHashes.containsKey(hash)) {
196+
return File(fileHashes[hash]!);
189197
}
190198
});
191199
app.listen(
192-
httpServerConfig['port']!,
193-
httpServerConfig['bind'] ?? '0.0.0.0',
200+
httpPort,
201+
httpBind,
194202
);
195203
}
196204

@@ -210,9 +218,9 @@ class FileSystemProviderObjectStore extends ObjectStore {
210218
Future<StorageLocation> provide(Multihash hash, List<int> types) async {
211219
return StorageLocation(
212220
3,
213-
// TODO Specify external URL and increase expiry
214-
['http://localhost:23432/hash/${hash.toBase64Url()}'],
215-
calculateExpiry(Duration(seconds: 30)),
221+
// TODO Increase expiry
222+
['$externalDownloadUrl/hash/${hash.toBase64Url()}'],
223+
calculateExpiry(Duration(minutes: 10)),
216224
);
217225
}
218226

0 commit comments

Comments
 (0)