fix: resolve actual folder sizes from file details

This commit is contained in:
ngfchl
2026-07-18 11:59:54 +08:00
parent 01a536af1b
commit cd598bfcda
2 changed files with 42 additions and 9 deletions
+36 -6
View File
@@ -1367,7 +1367,10 @@ class _SecondaryFilePaneState extends ConsumerState<_SecondaryFilePane> {
final entry = cache[file.id];
final cachedAt = int.tryParse(entry?['cachedAt']?.toString() ?? '');
final size = int.tryParse(entry?['size']?.toString() ?? '');
if (cachedAt != null && size != null && now - cachedAt <= ttl) {
if (cachedAt != null &&
size != null &&
size > 0 &&
now - cachedAt <= ttl) {
cached[file.id] = size;
} else {
queue.add(file);
@@ -1397,11 +1400,14 @@ class _SecondaryFilePaneState extends ConsumerState<_SecondaryFilePane> {
final folder = queue.removeLast();
try {
final detail = await api.fsDetail(folder.id);
final size = _extractFiles(detail)
.where((file) => file.id == folder.id)
.map((file) => file.size)
.whereType<int>()
.firstOrNull;
final size = _findIntDeep(detail, const [
'size',
'fileSize',
'resSize',
'totalSize',
'dirSize',
'folderSize',
]);
if (size == null) continue;
cache[folder.id] = {'size': size, 'cachedAt': now};
resolved[folder.id] = size;
@@ -1428,6 +1434,30 @@ class _SecondaryFilePaneState extends ConsumerState<_SecondaryFilePane> {
);
}
int? _findIntDeep(Map<String, dynamic> value, List<String> keys) {
for (final entry in value.entries) {
if (keys.contains(entry.key)) {
final parsed = int.tryParse(entry.value?.toString() ?? '');
if (parsed != null) return parsed;
}
if (entry.value is Map) {
final found = _findIntDeep(
Map<String, dynamic>.from(entry.value),
keys,
);
if (found != null) return found;
} else if (entry.value is List) {
for (final child in entry.value as List) {
if (child is Map) {
final found = _findIntDeep(Map<String, dynamic>.from(child), keys);
if (found != null) return found;
}
}
}
}
return null;
}
String? get _currentParentID => _path.isEmpty ? null : _path.last.id;
Future<void> _moveCloudFiles(List<CloudFile> files, String? parentID) async {
+6 -3
View File
@@ -247,7 +247,10 @@ class FileNotifier extends StateNotifier<FileState> {
final entry = cache[file.id];
final cachedAt = int.tryParse(entry?['cachedAt']?.toString() ?? '');
final cachedSize = int.tryParse(entry?['size']?.toString() ?? '');
if (cachedAt != null && cachedSize != null && now - cachedAt <= ttl) {
if (cachedAt != null &&
cachedSize != null &&
cachedSize > 0 &&
now - cachedAt <= ttl) {
known[file.id] = cachedSize;
} else {
pending.add(file);
@@ -285,7 +288,6 @@ class FileNotifier extends StateNotifier<FileState> {
orElse: () => null,
);
final size =
detailFile?.size ??
_findIntDeep(detail, const [
'size',
'fileSize',
@@ -293,7 +295,8 @@ class FileNotifier extends StateNotifier<FileState> {
'totalSize',
'dirSize',
'folderSize',
]);
]) ??
detailFile?.size;
if (size == null) continue;
cache[file.id] = {'size': size, 'cachedAt': now};
resolved[file.id] = size;