Skip to content

Commit

Permalink
fix(mobile): incorrect filename is retrieved during upload (#12990)
Browse files Browse the repository at this point in the history
* fix(mobile): incorrect filename is retrieve during upload

* use the same convention to get local id

* revert previous change

* pr feedback
  • Loading branch information
alextran1502 authored Sep 27, 2024
1 parent 3a37fc8 commit 03aa346
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mobile/lib/interfaces/asset_media.interface.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ abstract interface class IAssetMediaRepository {
Future<List<String>> deleteAll(List<String> ids);

Future<Asset?> get(String id);

/// Obtaining the correct original filename of the asset
Future<String?> getOriginalFilename(String id);
}
13 changes: 13 additions & 0 deletions mobile/lib/repositories/asset_media.repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,17 @@ class AssetMediaRepository implements IAssetMediaRepository {
asset.local = local;
return asset;
}

@override
Future<String?> getOriginalFilename(String id) async {
final entity = await AssetEntity.fromId(id);

if (entity == null) {
return null;
}

// titleAsync gets the correct original filename for some assets on iOS
// otherwise using the `entity.title` would return a random GUID
return await entity.titleAsync;
}
}
3 changes: 3 additions & 0 deletions mobile/lib/services/background.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import 'package:immich_mobile/models/backup/success_upload_asset.model.dart';
import 'package:immich_mobile/repositories/album.repository.dart';
import 'package:immich_mobile/repositories/album_api.repository.dart';
import 'package:immich_mobile/repositories/asset.repository.dart';
import 'package:immich_mobile/repositories/asset_media.repository.dart';
import 'package:immich_mobile/repositories/backup.repository.dart';
import 'package:immich_mobile/repositories/album_media.repository.dart';
import 'package:immich_mobile/repositories/file_media.repository.dart';
Expand Down Expand Up @@ -368,6 +369,7 @@ class BackgroundService {
BackupRepository backupAlbumRepository = BackupRepository(db);
AlbumMediaRepository albumMediaRepository = AlbumMediaRepository();
FileMediaRepository fileMediaRepository = FileMediaRepository();
AssetMediaRepository assetMediaRepository = AssetMediaRepository();
UserRepository userRepository = UserRepository(db);
UserApiRepository userApiRepository =
UserApiRepository(apiService.usersApi);
Expand Down Expand Up @@ -409,6 +411,7 @@ class BackgroundService {
albumService,
albumMediaRepository,
fileMediaRepository,
assetMediaRepository,
);

final selectedAlbums = backupService.selectedAlbumsQuery().findAllSync();
Expand Down
9 changes: 8 additions & 1 deletion mobile/lib/services/backup.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:immich_mobile/entities/backup_album.entity.dart';
import 'package:immich_mobile/entities/duplicated_asset.entity.dart';
import 'package:immich_mobile/entities/store.entity.dart';
import 'package:immich_mobile/interfaces/album_media.interface.dart';
import 'package:immich_mobile/interfaces/asset_media.interface.dart';
import 'package:immich_mobile/interfaces/file_media.interface.dart';
import 'package:immich_mobile/models/backup/backup_candidate.model.dart';
import 'package:immich_mobile/models/backup/current_upload_asset.model.dart';
Expand All @@ -21,6 +22,7 @@ import 'package:immich_mobile/providers/api.provider.dart';
import 'package:immich_mobile/providers/app_settings.provider.dart';
import 'package:immich_mobile/providers/db.provider.dart';
import 'package:immich_mobile/repositories/album_media.repository.dart';
import 'package:immich_mobile/repositories/asset_media.repository.dart';
import 'package:immich_mobile/repositories/file_media.repository.dart';
import 'package:immich_mobile/services/album.service.dart';
import 'package:immich_mobile/services/api.service.dart';
Expand All @@ -40,6 +42,7 @@ final backupServiceProvider = Provider(
ref.watch(albumServiceProvider),
ref.watch(albumMediaRepositoryProvider),
ref.watch(fileMediaRepositoryProvider),
ref.watch(assetMediaRepositoryProvider),
),
);

Expand All @@ -52,6 +55,7 @@ class BackupService {
final AlbumService _albumService;
final IAlbumMediaRepository _albumMediaRepository;
final IFileMediaRepository _fileMediaRepository;
final IAssetMediaRepository _assetMediaRepository;

BackupService(
this._apiService,
Expand All @@ -60,6 +64,7 @@ class BackupService {
this._albumService,
this._albumMediaRepository,
this._fileMediaRepository,
this._assetMediaRepository,
);

Future<List<String>?> getDeviceBackupAsset() async {
Expand Down Expand Up @@ -329,7 +334,9 @@ class BackupService {
}

if (file != null) {
String originalFileName = asset.fileName;
String? originalFileName =
await _assetMediaRepository.getOriginalFilename(asset.localId!);
originalFileName ??= asset.fileName;

if (asset.local!.isLivePhoto) {
if (livePhotoFile == null) {
Expand Down

0 comments on commit 03aa346

Please sign in to comment.