mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
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:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user