mirror of
https://github.com/immich-app/immich.git
synced 2025-11-12 09:36:50 -05:00
* fix: local sync task never runs on iOS * chore: rename ios register method * refactor from using dart callback to dart entrypoint + more logs * check if file exists before hashing * reschedule local sync task * chore: rename background worker logger * refactor: move file exists check inside repo --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
94 lines
2.5 KiB
Dart
94 lines
2.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:immich_mobile/domain/models/asset/base_asset.model.dart';
|
|
import 'package:logging/logging.dart';
|
|
import 'package:photo_manager/photo_manager.dart';
|
|
|
|
class StorageRepository {
|
|
const StorageRepository();
|
|
|
|
Future<File?> getFileForAsset(String assetId) async {
|
|
File? file;
|
|
final log = Logger('StorageRepository');
|
|
|
|
try {
|
|
final entity = await AssetEntity.fromId(assetId);
|
|
file = await entity?.originFile;
|
|
if (file == null) {
|
|
log.warning("Cannot get file for asset $assetId");
|
|
return null;
|
|
}
|
|
|
|
final exists = await file.exists();
|
|
if (!exists) {
|
|
log.warning("File for asset $assetId does not exist");
|
|
return null;
|
|
}
|
|
} catch (error, stackTrace) {
|
|
log.warning("Error getting file for asset $assetId", error, stackTrace);
|
|
}
|
|
return file;
|
|
}
|
|
|
|
Future<File?> getMotionFileForAsset(LocalAsset asset) async {
|
|
File? file;
|
|
final log = Logger('StorageRepository');
|
|
|
|
try {
|
|
final entity = await AssetEntity.fromId(asset.id);
|
|
file = await entity?.originFileWithSubtype;
|
|
if (file == null) {
|
|
log.warning(
|
|
"Cannot get motion file for asset ${asset.id}, name: ${asset.name}, created on: ${asset.createdAt}",
|
|
);
|
|
return null;
|
|
}
|
|
|
|
final exists = await file.exists();
|
|
if (!exists) {
|
|
log.warning("Motion file for asset ${asset.id} does not exist");
|
|
return null;
|
|
}
|
|
} catch (error, stackTrace) {
|
|
log.warning(
|
|
"Error getting motion file for asset ${asset.id}, name: ${asset.name}, created on: ${asset.createdAt}",
|
|
error,
|
|
stackTrace,
|
|
);
|
|
}
|
|
return file;
|
|
}
|
|
|
|
Future<AssetEntity?> getAssetEntityForAsset(LocalAsset asset) async {
|
|
final log = Logger('StorageRepository');
|
|
|
|
AssetEntity? entity;
|
|
|
|
try {
|
|
entity = await AssetEntity.fromId(asset.id);
|
|
if (entity == null) {
|
|
log.warning(
|
|
"Cannot get AssetEntity for asset ${asset.id}, name: ${asset.name}, created on: ${asset.createdAt}",
|
|
);
|
|
}
|
|
} catch (error, stackTrace) {
|
|
log.warning(
|
|
"Error getting AssetEntity for asset ${asset.id}, name: ${asset.name}, created on: ${asset.createdAt}",
|
|
error,
|
|
stackTrace,
|
|
);
|
|
}
|
|
return entity;
|
|
}
|
|
|
|
Future<void> clearCache() async {
|
|
final log = Logger('StorageRepository');
|
|
|
|
try {
|
|
await PhotoManager.clearFileCache();
|
|
} catch (error, stackTrace) {
|
|
log.warning("Error clearing cache", error, stackTrace);
|
|
}
|
|
}
|
|
}
|