mirror of
https://github.com/immich-app/immich.git
synced 2025-05-31 04:05:39 -04:00
fix: handle livePhotos using originFileWithSubType (#5602)
* fix: handle livePhotos using originFileWithSubType * remove livePhoto asset cache * fetch live photo video name from entity * fix: video file not detected * chore: pull main * fix: set correct header --------- Co-authored-by: shenlong-tanwen <139912620+shalong-tanwen@users.noreply.github.com> Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
parent
c8da1c07dc
commit
fb4b4e5895
@ -2,7 +2,6 @@ import 'dart:async';
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:cancellation_token_http/http.dart';
|
|
||||||
import 'package:collection/collection.dart';
|
import 'package:collection/collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||||
@ -227,6 +226,7 @@ class BackupService {
|
|||||||
final String deviceId = Store.get(StoreKey.deviceId);
|
final String deviceId = Store.get(StoreKey.deviceId);
|
||||||
final String savedEndpoint = Store.get(StoreKey.serverEndpoint);
|
final String savedEndpoint = Store.get(StoreKey.serverEndpoint);
|
||||||
File? file;
|
File? file;
|
||||||
|
File? livePhotoFile;
|
||||||
bool anyErrors = false;
|
bool anyErrors = false;
|
||||||
final List<String> duplicatedAssetIds = [];
|
final List<String> duplicatedAssetIds = [];
|
||||||
|
|
||||||
@ -249,7 +249,8 @@ class BackupService {
|
|||||||
|
|
||||||
for (var entity in assetsToUpload) {
|
for (var entity in assetsToUpload) {
|
||||||
try {
|
try {
|
||||||
final isAvailableLocally = await entity.isLocallyAvailable();
|
final isAvailableLocally =
|
||||||
|
await entity.isLocallyAvailable(isOrigin: true);
|
||||||
|
|
||||||
// Handle getting files from iCloud
|
// Handle getting files from iCloud
|
||||||
if (!isAvailableLocally && Platform.isIOS) {
|
if (!isAvailableLocally && Platform.isIOS) {
|
||||||
@ -271,11 +272,19 @@ class BackupService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
file = await entity.loadFile(progressHandler: pmProgressHandler);
|
file = await entity.loadFile(progressHandler: pmProgressHandler);
|
||||||
|
livePhotoFile = await entity.loadFile(
|
||||||
|
withSubtype: true,
|
||||||
|
progressHandler: pmProgressHandler,
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
if (entity.type == AssetType.video) {
|
if (entity.type == AssetType.video) {
|
||||||
file = await entity.originFile;
|
file = await entity.originFile;
|
||||||
} else {
|
} else {
|
||||||
file = await entity.originFile.timeout(const Duration(seconds: 5));
|
file = await entity.originFile.timeout(const Duration(seconds: 5));
|
||||||
|
if (entity.isLivePhoto) {
|
||||||
|
livePhotoFile = await entity.originFileWithSubtype
|
||||||
|
.timeout(const Duration(seconds: 5));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -311,9 +320,23 @@ class BackupService {
|
|||||||
req.files.add(assetRawUploadData);
|
req.files.add(assetRawUploadData);
|
||||||
|
|
||||||
if (entity.isLivePhoto) {
|
if (entity.isLivePhoto) {
|
||||||
var livePhotoRawUploadData = await _getLivePhotoFile(entity);
|
if (livePhotoFile != null) {
|
||||||
if (livePhotoRawUploadData != null) {
|
final livePhotoTitle = p.setExtension(
|
||||||
|
originalFileName,
|
||||||
|
p.extension(livePhotoFile.path),
|
||||||
|
);
|
||||||
|
final fileStream = livePhotoFile.openRead();
|
||||||
|
final livePhotoRawUploadData = http.MultipartFile(
|
||||||
|
"livePhotoData",
|
||||||
|
fileStream,
|
||||||
|
livePhotoFile.lengthSync(),
|
||||||
|
filename: livePhotoTitle,
|
||||||
|
);
|
||||||
req.files.add(livePhotoRawUploadData);
|
req.files.add(livePhotoRawUploadData);
|
||||||
|
} else {
|
||||||
|
_log.warning(
|
||||||
|
"Failed to obtain motion part of the livePhoto - $originalFileName",
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,6 +394,7 @@ class BackupService {
|
|||||||
} finally {
|
} finally {
|
||||||
if (Platform.isIOS) {
|
if (Platform.isIOS) {
|
||||||
file?.deleteSync();
|
file?.deleteSync();
|
||||||
|
livePhotoFile?.deleteSync();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -380,25 +404,6 @@ class BackupService {
|
|||||||
return !anyErrors;
|
return !anyErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<MultipartFile?> _getLivePhotoFile(AssetEntity entity) async {
|
|
||||||
var motionFilePath = await entity.getMediaUrl();
|
|
||||||
|
|
||||||
if (motionFilePath != null) {
|
|
||||||
var validPath = motionFilePath.replaceAll('file://', '');
|
|
||||||
var motionFile = File(validPath);
|
|
||||||
var fileStream = motionFile.openRead();
|
|
||||||
String fileName = p.basename(motionFile.path);
|
|
||||||
return http.MultipartFile(
|
|
||||||
"livePhotoData",
|
|
||||||
fileStream,
|
|
||||||
motionFile.lengthSync(),
|
|
||||||
filename: fileName,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
String _getAssetType(AssetType assetType) {
|
String _getAssetType(AssetType assetType) {
|
||||||
switch (assetType) {
|
switch (assetType) {
|
||||||
case AssetType.audio:
|
case AssetType.audio:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user