浏览代码

Fix updation for live photos

Neeraj Gupta 1 年之前
父节点
当前提交
dfa5569d76
共有 3 个文件被更改,包括 42 次插入10 次删除
  1. 9 5
      lib/db/files_db.dart
  2. 27 3
      lib/services/local_file_update_service.dart
  3. 6 2
      lib/utils/file_uploader_util.dart

+ 9 - 5
lib/db/files_db.dart

@@ -879,13 +879,14 @@ class FilesDB {
     );
   }
 
-  Future<int> updateUploadedFile(
+  Future<int> markFilesForReUpload(
+    int ownerID,
     String localID,
     String? title,
     Location? location,
     int creationTime,
     int modificationTime,
-    int? updationTime,
+    FileType fileType,
   ) async {
     final db = await instance.database;
     return await db.update(
@@ -896,10 +897,13 @@ class FilesDB {
         columnLongitude: location?.longitude,
         columnCreationTime: creationTime,
         columnModificationTime: modificationTime,
-        columnUpdationTime: updationTime,
+        // #hack reset updation time to null for re-upload
+        columnUpdationTime: null,
+        columnFileType: getInt(fileType),
       },
-      where: '$columnLocalID = ?',
-      whereArgs: [localID],
+      where:
+          '$columnLocalID = ? AND ($columnOwnerID = ? OR $columnOwnerID IS NULL)',
+      whereArgs: [localID, ownerID],
     );
   }
 

+ 27 - 3
lib/services/local_file_update_service.dart

@@ -8,6 +8,7 @@ import 'package:photos/core/errors.dart';
 import 'package:photos/db/file_updation_db.dart';
 import 'package:photos/db/files_db.dart';
 import 'package:photos/models/file.dart' as ente;
+import "package:photos/models/file_type.dart";
 import 'package:photos/utils/file_uploader_util.dart';
 import 'package:photos/utils/file_util.dart';
 import 'package:shared_preferences/shared_preferences.dart';
@@ -141,18 +142,41 @@ class LocalFileUpdateService {
             "Marking for file update as hash did not match ${file.tag}",
           );
           await clearCache(file);
-          await FilesDB.instance.updateUploadedFile(
+          await FilesDB.instance.markFilesForReUpload(
+            userID,
             file.localID!,
             file.title,
             file.location,
             file.creationTime!,
             file.modificationTime!,
-            null,
+            file.fileType,
           );
         }
         processedIDs.add(file.localID!);
       } on InvalidFileError catch (e) {
-        _logger.fine("Failed to check hash due to invalidfile ${file.tag}", e);
+        if (e.reason == InvalidReason.livePhotoToImageTypeChanged ||
+            e.reason == InvalidReason.imageToLivePhotoTypeChanged) {
+
+          late FileType fileType;
+          if (e.reason == InvalidReason.livePhotoToImageTypeChanged) {
+            fileType = FileType.image;
+          } else if (e.reason == InvalidReason.imageToLivePhotoTypeChanged) {
+            fileType = FileType.livePhoto;
+          }
+          final int count = await FilesDB.instance.markFilesForReUpload(
+            userID,
+            file.localID!,
+            file.title,
+            file.location,
+            file.creationTime!,
+            file.modificationTime!,
+            fileType,
+          );
+          _logger.fine('fileType changed for ${file.tag} to ${e.reason} for '
+              '$count files');
+        } else {
+          _logger.severe("failed to check hash: invalid file ${file.tag}", e);
+        }
         processedIDs.add(file.localID!);
       } catch (e) {
         _logger.severe("Failed to check hash", e);

+ 6 - 2
lib/utils/file_uploader_util.dart

@@ -197,11 +197,15 @@ void _assertFileType(AssetEntity asset, ente.File file) {
   if (io.Platform.isIOS || io.Platform.isMacOS) {
     if (assetType == FileType.image && file.fileType == FileType.livePhoto) {
       throw InvalidFileError(
-          'id ${asset.id}', InvalidReason.imageToLivePhotoTypeChanged,);
+        'id ${asset.id}',
+        InvalidReason.livePhotoToImageTypeChanged,
+      );
     } else if (assetType == FileType.livePhoto &&
         file.fileType == FileType.image) {
       throw InvalidFileError(
-          'id ${asset.id}', InvalidReason.livePhotoToImageTypeChanged,);
+        'id ${asset.id}',
+        InvalidReason.imageToLivePhotoTypeChanged,
+      );
     }
   }
   throw InvalidFileError(