listFolderFiles method
List files in folder uuid, using cache when available.
Implementation
Future<List<Map<String, dynamic>>> listFolderFiles(
String uuid, {
bool detailed = false,
required FilenApi api,
required FilenCrypto crypto,
required List<String> masterKeys,
}) async {
final cached = fileCache[uuid];
if (cached != null && _isValid(cached)) {
api.log('Using cached file list for $uuid');
return List<Map<String, dynamic>>.from(cached.items);
}
final response = await api.post('/v3/dir/content', {'uuid': uuid});
final d = response['data']['uploads'] ?? [];
final res = await Future.wait((d as List).map((f) async {
try {
final m =
json.decode(await crypto.tryDecrypt(f['metadata'], masterKeys));
return {
'type': 'file',
'name': m['name'],
'uuid': f['uuid'],
'size': m['size'],
'parent': f['parent'],
'timestamp': f['timestamp'],
'lastModified': m['lastModified'],
};
} catch (_) {
return {
'type': 'file',
'name': '[Encrypted]',
'uuid': f['uuid'],
'size': 0,
};
}
}).toList());
final typedRes = res.cast<Map<String, dynamic>>();
fileCache[uuid] = CacheEntry(items: typedRes, timestamp: _now());
if (!detailed) {
return typedRes
.map((item) => {
'type': item['type'],
'name': item['name'],
'uuid': item['uuid'],
'size': item['size'],
})
.toList();
}
return typedRes;
}