listFoldersAsync method
List subfolders of uuid, using cache when available.
Implementation
Future<List<Map<String, dynamic>>> listFoldersAsync(
String uuid, {
bool detailed = false,
required FilenApi api,
required FilenCrypto crypto,
required List<String> masterKeys,
}) async {
final cached = folderCache[uuid];
if (cached != null && _isValid(cached)) {
api.log('Using cached folder 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']['folders'] ?? [];
List<Map<String, dynamic>> res = [];
for (var f in d) {
try {
var dec = await crypto.tryDecrypt(f['name'], masterKeys);
var name = dec.startsWith('{') ? json.decode(dec)['name'] : dec;
res.add({
'type': 'folder',
'name': name,
'uuid': f['uuid'],
'size': 0,
'parent': f['parent'],
'timestamp': f['timestamp'],
'lastModified': f['lastModified'],
});
} catch (_) {
res.add({
'type': 'folder',
'name': '[Encrypted]',
'uuid': f['uuid'],
'size': 0,
});
}
}
folderCache[uuid] = CacheEntry(items: res, timestamp: _now());
if (!detailed) {
return res
.map((item) => {
'type': item['type'],
'name': item['name'],
'uuid': item['uuid'],
'size': item['size'],
})
.toList();
}
return res;
}