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/asset.entity.dart' as asset_entity;
|
||||||
import 'package:immich_mobile/entities/store.entity.dart';
|
import 'package:immich_mobile/entities/store.entity.dart';
|
||||||
import 'package:immich_mobile/extensions/build_context_extensions.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/extensions/response_extensions.dart';
|
||||||
import 'package:immich_mobile/repositories/asset_api.repository.dart';
|
import 'package:immich_mobile/repositories/asset_api.repository.dart';
|
||||||
import 'package:immich_mobile/utils/hash.dart';
|
import 'package:immich_mobile/utils/hash.dart';
|
||||||
|
|
@ -72,6 +73,7 @@ class AssetMediaRepository {
|
||||||
// TODO: make this more efficient
|
// TODO: make this more efficient
|
||||||
Future<int> shareAssets(List<BaseAsset> assets, BuildContext context) async {
|
Future<int> shareAssets(List<BaseAsset> assets, BuildContext context) async {
|
||||||
final downloadedXFiles = <XFile>[];
|
final downloadedXFiles = <XFile>[];
|
||||||
|
final tempFiles = <File>[];
|
||||||
|
|
||||||
for (var asset in assets) {
|
for (var asset in assets) {
|
||||||
final localId = (asset is LocalAsset)
|
final localId = (asset is LocalAsset)
|
||||||
|
|
@ -82,6 +84,9 @@ class AssetMediaRepository {
|
||||||
if (localId != null) {
|
if (localId != null) {
|
||||||
File? f = await AssetEntity(id: localId, width: 1, height: 1, typeInt: 0).originFile;
|
File? f = await AssetEntity(id: localId, width: 1, height: 1, typeInt: 0).originFile;
|
||||||
downloadedXFiles.add(XFile(f!.path));
|
downloadedXFiles.add(XFile(f!.path));
|
||||||
|
if (CurrentPlatform.isIOS) {
|
||||||
|
tempFiles.add(f);
|
||||||
|
}
|
||||||
} else if (asset is RemoteAsset) {
|
} else if (asset is RemoteAsset) {
|
||||||
final tempDir = await getTemporaryDirectory();
|
final tempDir = await getTemporaryDirectory();
|
||||||
final name = asset.name;
|
final name = asset.name;
|
||||||
|
|
@ -95,6 +100,7 @@ class AssetMediaRepository {
|
||||||
|
|
||||||
await tempFile.writeAsBytes(res.bodyBytes);
|
await tempFile.writeAsBytes(res.bodyBytes);
|
||||||
downloadedXFiles.add(XFile(tempFile.path));
|
downloadedXFiles.add(XFile(tempFile.path));
|
||||||
|
tempFiles.add(tempFile);
|
||||||
} else {
|
} else {
|
||||||
_log.warning("Asset type not supported for sharing: $asset");
|
_log.warning("Asset type not supported for sharing: $asset");
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -113,9 +119,9 @@ class AssetMediaRepository {
|
||||||
downloadedXFiles,
|
downloadedXFiles,
|
||||||
sharePositionOrigin: Rect.fromPoints(Offset.zero, Offset(size.width / 3, size.height)),
|
sharePositionOrigin: Rect.fromPoints(Offset.zero, Offset(size.width / 3, size.height)),
|
||||||
).then((result) async {
|
).then((result) async {
|
||||||
for (var file in downloadedXFiles) {
|
for (var file in tempFiles) {
|
||||||
try {
|
try {
|
||||||
await File(file.path).delete();
|
await file.delete();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
_log.warning("Failed to delete temporary file: ${file.path}", e);
|
_log.warning("Failed to delete temporary file: ${file.path}", e);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue