mirror of
https://github.com/immich-app/immich.git
synced 2025-01-10 05:46:46 +01:00
e57e279fe1
* Share unique assets * Style share preparing dialog * Share assets from multiselect * Fix i18n * Use navigator like in delete dialog * Center bottom-bar buttons
45 lines
1.2 KiB
Dart
45 lines
1.2 KiB
Dart
|
|
import 'dart:io';
|
|
|
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
|
import 'package:immich_mobile/shared/providers/api.provider.dart';
|
|
import 'package:openapi/api.dart';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:share_plus/share_plus.dart';
|
|
import 'package:path/path.dart' as p;
|
|
import 'api.service.dart';
|
|
|
|
final shareServiceProvider =
|
|
Provider((ref) => ShareService(ref.watch(apiServiceProvider)));
|
|
|
|
class ShareService {
|
|
final ApiService _apiService;
|
|
|
|
ShareService(this._apiService);
|
|
|
|
Future<void> shareAsset(AssetResponseDto asset) async {
|
|
await shareAssets([asset]);
|
|
}
|
|
|
|
Future<void> shareAssets(List<AssetResponseDto> assets) async {
|
|
final downloadedFilePaths = assets.map((asset) async {
|
|
final res = await _apiService.assetApi.downloadFileWithHttpInfo(
|
|
asset.deviceAssetId,
|
|
asset.deviceId,
|
|
isThumb: false,
|
|
isWeb: false,
|
|
);
|
|
|
|
final fileName = p.basename(asset.originalPath);
|
|
|
|
final tempDir = await getTemporaryDirectory();
|
|
final tempFile = await File('${tempDir.path}/$fileName').create();
|
|
tempFile.writeAsBytesSync(res.bodyBytes);
|
|
|
|
return tempFile.path;
|
|
});
|
|
|
|
Share.shareFiles(await Future.wait(downloadedFilePaths));
|
|
}
|
|
|
|
}
|