diff --git a/mobile/lib/db/upload_locks_db.dart b/mobile/lib/db/upload_locks_db.dart index 408d65b72..10bd5ade6 100644 --- a/mobile/lib/db/upload_locks_db.dart +++ b/mobile/lib/db/upload_locks_db.dart @@ -23,7 +23,8 @@ class UploadLocksDB { columnLocalID: "local_id", columnFileHash: "file_hash", columnCollectionID: "collection_id", - columnEncryptedFilePath: "encrypted_file_path", + // todo: neeraj change the name before merging + columnEncryptedFileName: "encrypted_file_path", columnEncryptedFileSize: "encrypted_file_size", columnEncryptedFileKey: "encrypted_file_key", columnFileEncryptionNonce: "file_encryption_nonce", @@ -95,7 +96,7 @@ class UploadLocksDB { ${_trackUploadTable.columnLocalID} TEXT NOT NULL, ${_trackUploadTable.columnFileHash} TEXT NOT NULL, ${_trackUploadTable.columnCollectionID} INTEGER NOT NULL, - ${_trackUploadTable.columnEncryptedFilePath} TEXT NOT NULL, + ${_trackUploadTable.columnEncryptedFileName} TEXT NOT NULL, ${_trackUploadTable.columnEncryptedFileSize} INTEGER NOT NULL, ${_trackUploadTable.columnEncryptedFileKey} TEXT NOT NULL, ${_trackUploadTable.columnFileEncryptionNonce} TEXT NOT NULL, @@ -308,7 +309,7 @@ class UploadLocksDB { String fileHash, int collectionID, MultipartUploadURLs urls, - String encryptedFilePath, + String encryptedFileName, int fileSize, String fileKey, String fileNonce, @@ -326,7 +327,7 @@ class UploadLocksDB { _trackUploadTable.columnCollectionID: collectionID, _trackUploadTable.columnObjectKey: objectKey, _trackUploadTable.columnCompleteUrl: urls.completeURL, - _trackUploadTable.columnEncryptedFilePath: encryptedFilePath, + _trackUploadTable.columnEncryptedFileName: encryptedFileName, _trackUploadTable.columnEncryptedFileSize: fileSize, _trackUploadTable.columnEncryptedFileKey: fileKey, _trackUploadTable.columnFileEncryptionNonce: fileNonce, @@ -397,14 +398,14 @@ class UploadLocksDB { ); } - Future isEncryptedPathSafeToDelete(String encryptedPath) { + Future isEncryptedPathSafeToDelete(String encryptedFileName) { // If lastAttemptedAt exceeds 3 days or createdAt exceeds 7 days final db = instance.database; return db.then((db) async { final rows = await db.query( _trackUploadTable.table, - where: '${_trackUploadTable.columnEncryptedFilePath} = ?', - whereArgs: [encryptedPath], + where: '${_trackUploadTable.columnEncryptedFileName} = ?', + whereArgs: [encryptedFileName], ); if (rows.isEmpty) { return true; @@ -420,7 +421,7 @@ class UploadLocksDB { }); } - Future getEncryptedPath( + Future getEncryptedFileName( String localId, String fileHash, int collectionID, @@ -437,7 +438,7 @@ class UploadLocksDB { throw Exception("No cached links found for $localId and $fileHash"); } final row = rows.first; - return row[_trackUploadTable.columnEncryptedFilePath] as String; + return row[_trackUploadTable.columnEncryptedFileName] as String; }); } } diff --git a/mobile/lib/module/upload/service/multipart.dart b/mobile/lib/module/upload/service/multipart.dart index 1cf4f092b..f2a9259aa 100644 --- a/mobile/lib/module/upload/service/multipart.dart +++ b/mobile/lib/module/upload/service/multipart.dart @@ -91,7 +91,7 @@ class MultiPartUploader { String fileHash, int collectionID, MultipartUploadURLs urls, - String encryptedFilePath, + String encryptedFileName, int fileSize, Uint8List fileKey, Uint8List fileNonce, @@ -109,7 +109,7 @@ class MultiPartUploader { fileHash, collectionID, urls, - encryptedFilePath, + encryptedFileName, fileSize, CryptoUtil.bin2base64(encryptedResult.encryptedData!), CryptoUtil.bin2base64(fileNonce), @@ -192,7 +192,7 @@ class MultiPartUploader { _logger.info( "Uploading part ${i + 1} / $partsLength of size $fileSize bytes (total size $encFileLength).", ); - if (kDebugMode && count > 1) { + if (kDebugMode && count > 3) { throw Exception( 'In debug mode, only one part will be uploaded at a time.', ); diff --git a/mobile/lib/utils/file_uploader.dart b/mobile/lib/utils/file_uploader.dart index fe374386a..c3cb5f8c6 100644 --- a/mobile/lib/utils/file_uploader.dart +++ b/mobile/lib/utils/file_uploader.dart @@ -453,6 +453,7 @@ class FileUploader { } final tempDirectory = Configuration.instance.getTempDirectory(); + final uploadPrefix = '$tempDirectory$uploadTempFilePrefix'; MediaUploadData? mediaUploadData; mediaUploadData = await getUploadDataFromEnteFile(file); @@ -466,14 +467,13 @@ class FileUploader { final String uniqueID = const Uuid().v4().toString(); final encryptedFilePath = multipartEntryExists - ? await _uploadLocks.getEncryptedPath( + ? '$uploadPrefix${await _uploadLocks.getEncryptedFileName( lockKey, mediaUploadData.hashData!.fileHash!, collectionID, - ) - : '$tempDirectory$uploadTempFilePrefix${uniqueID}_file.encrypted'; - final encryptedThumbnailPath = - '$tempDirectory$uploadTempFilePrefix${uniqueID}_thumb.encrypted'; + )}' + : '$uploadPrefix${uniqueID}_file.encrypted'; + final encryptedThumbnailPath = '$uploadPrefix${uniqueID}_thumb.encrypted'; var uploadCompleted = false; // This flag is used to decide whether to clear the iOS origin file cache // or not. @@ -592,12 +592,13 @@ class FileUploader { } else { final fileUploadURLs = await _multiPartUploader.getMultipartUploadURLs(count); + final encFileName = encryptedFilePath.replaceAll(uploadPrefix, ''); await _multiPartUploader.createTableEntry( lockKey, mediaUploadData.hashData!.fileHash!, collectionID, fileUploadURLs, - encryptedFilePath, + encFileName, await encryptedFile.length(), fileAttributes.key!, fileAttributes.header!,