1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-19 00:32:49 +02:00
immich/mobile/lib/modules/trash/services/trash.service.dart
Conner Hnatiuk 3e03f5348f
fix(mobile): restore button in asset viewer (#8919)
* fix:(mobile): spell error in top_control_app_bar.dart in function buildAddToAlbumButtom

* fix(mobile): add restore button to individual image view of trashed assets

* formatting
2024-04-26 01:01:03 -05:00

63 lines
1.7 KiB
Dart

import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:immich_mobile/shared/models/asset.dart';
import 'package:immich_mobile/shared/providers/api.provider.dart';
import 'package:immich_mobile/shared/services/api.service.dart';
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();
await _apiService.trashApi.restoreAssets(BulkIdsDto(ids: remoteIds));
return true;
} catch (error, stack) {
_log.severe("Cannot restore assets", error, stack);
return false;
}
}
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;
}
}
Future<void> emptyTrash() async {
try {
await _apiService.trashApi.emptyTrash();
} catch (error, stack) {
_log.severe("Cannot empty trash", error, stack);
}
}
Future<void> restoreTrash() async {
try {
await _apiService.trashApi.restoreTrash();
} catch (error, stack) {
_log.severe("Cannot restore trash", error, stack);
}
}
}