fix(mobile): self-heal stale linked album cache on 400

if the server forgets an album that mobile still has cached, every
upload hits 400 on addAssets and spams severe forever. catch that
400, drop the cache row, fk cascade nulls the link. next manage pass
recreates or re-links by name.
This commit is contained in:
Santo Shakil
2026-05-09 00:33:04 +06:00
parent 832ed4d015
commit 1120caca10
2 changed files with 51 additions and 25 deletions
@@ -42,17 +42,24 @@ class DriftAlbumApiRepository extends ApiRepository {
}
Future<({List<String> added, List<String> failed})> addAssets(String albumId, Iterable<String> assetIds) async {
final response = await checkNull(_api.addAssetsToAlbum(albumId, BulkIdsDto(ids: assetIds.toList())));
final List<String> added = [], failed = [];
for (final dto in response) {
if (dto.success) {
added.add(dto.id);
} else {
failed.add(dto.id);
try {
final response = await checkNull(_api.addAssetsToAlbum(albumId, BulkIdsDto(ids: assetIds.toList())));
final List<String> added = [], failed = [];
for (final dto in response) {
if (dto.success) {
added.add(dto.id);
} else {
failed.add(dto.id);
}
}
}
return (added: added, failed: failed);
return (added: added, failed: failed);
} on ApiException catch (e) {
if (e.code == 400 && (e.message?.contains('"message":"Album not found"') ?? false)) {
throw RemoteAlbumNotFoundException(albumId);
}
rethrow;
}
}
Future<RemoteAlbum> updateAlbum(
@@ -104,6 +111,14 @@ class DriftAlbumApiRepository extends ApiRepository {
}
}
class RemoteAlbumNotFoundException implements Exception {
final String albumId;
const RemoteAlbumNotFoundException(this.albumId);
@override
String toString() => 'RemoteAlbumNotFoundException: $albumId';
}
extension on AlbumResponseDto {
RemoteAlbum toRemoteAlbum(final UserDto user) {
return RemoteAlbum(