feat(mobile): upload image assets before videos (#3872)

* feat(mobile): upload image assets before videos

* mobile: sort by creation date before uploading assets
This commit is contained in:
shalong-tanwen 2023-08-27 07:18:17 +00:00 committed by GitHub
parent cb391342d7
commit 912a13ea0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -218,7 +218,18 @@ class BackupService {
bool anyErrors = false; bool anyErrors = false;
final List<String> duplicatedAssetIds = []; final List<String> duplicatedAssetIds = [];
for (var entity in assetList) { // Upload images before video assets
// these are further sorted by using their creation date so the upload goes as follows
// older images -> latest images -> older videos -> latest videos
List<AssetEntity> sortedAssets = assetList.sorted(
(a, b) {
final cmp = a.typeInt - b.typeInt;
if (cmp != 0) return cmp;
return a.createDateTime.compareTo(b.createDateTime);
},
);
for (var entity in sortedAssets) {
try { try {
if (entity.type == AssetType.video) { if (entity.type == AssetType.video) {
file = await entity.originFile; file = await entity.originFile;
@ -248,7 +259,8 @@ class BackupService {
req.fields['deviceAssetId'] = entity.id; req.fields['deviceAssetId'] = entity.id;
req.fields['deviceId'] = deviceId; req.fields['deviceId'] = deviceId;
req.fields['fileCreatedAt'] = entity.createDateTime.toUtc().toIso8601String(); req.fields['fileCreatedAt'] =
entity.createDateTime.toUtc().toIso8601String();
req.fields['fileModifiedAt'] = req.fields['fileModifiedAt'] =
entity.modifiedDateTime.toUtc().toIso8601String(); entity.modifiedDateTime.toUtc().toIso8601String();
req.fields['isFavorite'] = entity.isFavorite.toString(); req.fields['isFavorite'] = entity.isFavorite.toString();