2023-10-06 09:01:14 +02:00
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
2024-05-01 04:36:40 +02:00
|
|
|
import 'package:immich_mobile/entities/asset.entity.dart';
|
2024-05-02 22:59:14 +02:00
|
|
|
import 'package:immich_mobile/providers/api.provider.dart';
|
|
|
|
import 'package:immich_mobile/services/api.service.dart';
|
2023-10-06 09:01:14 +02:00
|
|
|
import 'package:logging/logging.dart';
|
|
|
|
import 'package:openapi/api.dart';
|
|
|
|
|
|
|
|
final trashServiceProvider = Provider<TrashService>((ref) {
|
|
|
|
return TrashService(
|
|
|
|
ref.watch(apiServiceProvider),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
class TrashService {
|
|
|
|
final _log = Logger("TrashService");
|
|
|
|
|
|
|
|
final ApiService _apiService;
|
|
|
|
|
|
|
|
TrashService(this._apiService);
|
|
|
|
|
|
|
|
Future<bool> restoreAssets(Iterable<Asset> assetList) async {
|
|
|
|
try {
|
|
|
|
List<String> remoteIds =
|
|
|
|
assetList.where((a) => a.isRemote).map((e) => e.remoteId!).toList();
|
2024-02-08 22:57:54 +01:00
|
|
|
await _apiService.trashApi.restoreAssets(BulkIdsDto(ids: remoteIds));
|
2023-10-06 09:01:14 +02:00
|
|
|
return true;
|
|
|
|
} catch (error, stack) {
|
2024-02-24 04:38:57 +01:00
|
|
|
_log.severe("Cannot restore assets", error, stack);
|
2023-10-06 09:01:14 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-26 08:01:03 +02:00
|
|
|
Future<bool> restoreAsset(Asset asset) async {
|
|
|
|
try {
|
|
|
|
if (asset.isRemote) {
|
|
|
|
List<String> remoteId = [asset.remoteId!];
|
|
|
|
|
|
|
|
await _apiService.trashApi.restoreAssets(BulkIdsDto(ids: remoteId));
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
} catch (error, stack) {
|
|
|
|
_log.severe("Cannot restore assets", error, stack);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-06 09:01:14 +02:00
|
|
|
Future<void> emptyTrash() async {
|
|
|
|
try {
|
2024-02-08 22:57:54 +01:00
|
|
|
await _apiService.trashApi.emptyTrash();
|
2023-10-06 09:01:14 +02:00
|
|
|
} catch (error, stack) {
|
2024-02-24 04:38:57 +01:00
|
|
|
_log.severe("Cannot empty trash", error, stack);
|
2023-10-06 09:01:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> restoreTrash() async {
|
|
|
|
try {
|
2024-02-08 22:57:54 +01:00
|
|
|
await _apiService.trashApi.restoreTrash();
|
2023-10-06 09:01:14 +02:00
|
|
|
} catch (error, stack) {
|
2024-02-24 04:38:57 +01:00
|
|
|
_log.severe("Cannot restore trash", error, stack);
|
2023-10-06 09:01:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|