Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Fix only attempt to re-upload in owned collection (#1555)

Neeraj Guptafe2bcc043804
diff --git a/lib/db/files_db.dart b/lib/db/files_db.dart
index bf5b5991c2..4864130b2e 100644
--- a/lib/db/files_db.dart
+++ b/lib/db/files_db.dart
@@ -789,7 +789,7 @@ class FilesDB {
return uploadedFileIDs;
}
- Future<EnteFile?> getUploadedLocalFileInAnyCollection(
+ Future<List<EnteFile>> getFilesInAllCollection(
int uploadedFileID,
int userID,
) async {
@@ -802,12 +802,11 @@ class FilesDB {
userID,
uploadedFileID,
],
- limit: 1,
);
if (results.isEmpty) {
- return null;
+ return <EnteFile>[];
}
- return convertToFiles(results)[0];
+ return convertToFiles(results);
}
Future<Set<String>> getExistingLocalFileIDs(int ownerID) async {
diff --git a/lib/models/file/extensions/file_props.dart b/lib/models/file/extensions/file_props.dart
index 2ecffd1ab6..b3f5ae672a 100644
--- a/lib/models/file/extensions/file_props.dart
+++ b/lib/models/file/extensions/file_props.dart
@@ -2,6 +2,7 @@ import "package:photos/core/configuration.dart";
import "package:photos/models/file/file.dart";
import "package:photos/models/file/file_type.dart";
import "package:photos/models/file/trash_file.dart";
+import "package:photos/services/collections_service.dart";
extension FilePropsExtn on EnteFile {
bool get isLivePhoto => fileType == FileType.livePhoto;
@@ -21,4 +22,14 @@ extension FilePropsExtn on EnteFile {
bool get isCollect => uploaderName != null;
String? get uploaderName => pubMagicMetadata?.uploaderName;
+
+ bool canReUpload(int userID) =>
+ localID != null &&
+ localID!.isNotEmpty &&
+ isOwner &&
+ collectionID != null &&
+ (CollectionsService.instance
+ .getCollectionByID(collectionID!)
+ ?.isOwner(userID) ??
+ false);
}
diff --git a/lib/services/remote_sync_service.dart b/lib/services/remote_sync_service.dart
index 7270ab52d0..b54b1e1088 100644
--- a/lib/services/remote_sync_service.dart
+++ b/lib/services/remote_sync_service.dart
@@ -552,12 +552,27 @@ class RemoteSyncService {
.info("Skipping some updated files as we are throttling uploads");
break;
}
- final file = await _db.getUploadedLocalFileInAnyCollection(
+ final allFiles = await _db.getFilesInAllCollection(
uploadedFileID,
ownerID,
);
- if (file != null) {
- _uploadFile(file, file.collectionID!, futures);
+ if (allFiles.isEmpty) {
+ _logger.warning("No files found for uploadedFileID $uploadedFileID");
+ continue;
+ }
+ EnteFile? fileInCollectionOwnedByUser;
+ for (final file in allFiles) {
+ if (file.canReUpload(ownerID)) {
+ fileInCollectionOwnedByUser = file;
+ break;
+ }
+ }
+ if (fileInCollectionOwnedByUser != null) {
+ _uploadFile(
+ fileInCollectionOwnedByUser,
+ fileInCollectionOwnedByUser.collectionID!,
+ futures,
+ );
}
}