sync media cache after file renames

This commit is contained in:
ngfchl
2026-07-18 21:03:03 +08:00
parent b505be1da8
commit a3a9ab9c8d
5 changed files with 153 additions and 9 deletions
+7 -3
View File
@@ -625,19 +625,23 @@ class FileNotifier extends StateNotifier<FileState> {
}
}
Future<void> renameFile(CloudFile file, String newName) async {
if (_api == null) return;
Future<bool> renameFile(CloudFile file, String newName) async {
if (_api == null) return false;
try {
await _api!.fsRename(file.id, newName);
final renamed = file.copyWith(name: newName);
state = state.copyWith(statusMessage: '重命名成功');
await FileMetadataCache.updateFolderChildren(
_currentParentID,
addOrReplace: [file.copyWith(name: newName)],
addOrReplace: [renamed],
);
await FileMetadataCache.cacheFiles([renamed]);
await _invalidateListCache(_currentParentID);
await loadFiles(parentID: _currentParentID);
return true;
} catch (e) {
state = state.copyWith(errorMessage: e.toString());
return false;
}
}