mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
fix: do not delete asset on share (#22578)
fix: do not delete local asset on share Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com>
This commit is contained in:
parent
00ce6354f0
commit
5ece0e5e56
1 changed files with 8 additions and 2 deletions
|
|
@ -8,6 +8,7 @@ import 'package:immich_mobile/domain/models/store.model.dart';
|
|||
import 'package:immich_mobile/entities/asset.entity.dart' as asset_entity;
|
||||
import 'package:immich_mobile/entities/store.entity.dart';
|
||||
import 'package:immich_mobile/extensions/build_context_extensions.dart';
|
||||
import 'package:immich_mobile/extensions/platform_extensions.dart';
|
||||
import 'package:immich_mobile/extensions/response_extensions.dart';
|
||||
import 'package:immich_mobile/repositories/asset_api.repository.dart';
|
||||
import 'package:immich_mobile/utils/hash.dart';
|
||||
|
|
@ -72,6 +73,7 @@ class AssetMediaRepository {
|
|||
// TODO: make this more efficient
|
||||
Future<int> shareAssets(List<BaseAsset> assets, BuildContext context) async {
|
||||
final downloadedXFiles = <XFile>[];
|
||||
final tempFiles = <File>[];
|
||||
|
||||
for (var asset in assets) {
|
||||
final localId = (asset is LocalAsset)
|
||||
|
|
@ -82,6 +84,9 @@ class AssetMediaRepository {
|
|||
if (localId != null) {
|
||||
File? f = await AssetEntity(id: localId, width: 1, height: 1, typeInt: 0).originFile;
|
||||
downloadedXFiles.add(XFile(f!.path));
|
||||
if (CurrentPlatform.isIOS) {
|
||||
tempFiles.add(f);
|
||||
}
|
||||
} else if (asset is RemoteAsset) {
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
final name = asset.name;
|
||||
|
|
@ -95,6 +100,7 @@ class AssetMediaRepository {
|
|||
|
||||
await tempFile.writeAsBytes(res.bodyBytes);
|
||||
downloadedXFiles.add(XFile(tempFile.path));
|
||||
tempFiles.add(tempFile);
|
||||
} else {
|
||||
_log.warning("Asset type not supported for sharing: $asset");
|
||||
continue;
|
||||
|
|
@ -113,9 +119,9 @@ class AssetMediaRepository {
|
|||
downloadedXFiles,
|
||||
sharePositionOrigin: Rect.fromPoints(Offset.zero, Offset(size.width / 3, size.height)),
|
||||
).then((result) async {
|
||||
for (var file in downloadedXFiles) {
|
||||
for (var file in tempFiles) {
|
||||
try {
|
||||
await File(file.path).delete();
|
||||
await file.delete();
|
||||
} catch (e) {
|
||||
_log.warning("Failed to delete temporary file: ${file.path}", e);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue