mirror of
https://github.com/ente-io/ente.git
synced 2025-08-13 09:47:17 +00:00
[mob] Compute encFileSize just once
This commit is contained in:
committed by
Neeraj Gupta
parent
138515da02
commit
1b6dbbc288
@@ -538,6 +538,8 @@ class FileUploader {
|
|||||||
: '$tempDirectory$uploadTempFilePrefix${uniqueID}_file.encrypted';
|
: '$tempDirectory$uploadTempFilePrefix${uniqueID}_file.encrypted';
|
||||||
final encryptedThumbnailPath =
|
final encryptedThumbnailPath =
|
||||||
'$tempDirectory$uploadTempFilePrefix${uniqueID}_thumb.encrypted';
|
'$tempDirectory$uploadTempFilePrefix${uniqueID}_thumb.encrypted';
|
||||||
|
late final int encFileSize;
|
||||||
|
late final int encThumbSize;
|
||||||
|
|
||||||
var uploadCompleted = false;
|
var uploadCompleted = false;
|
||||||
// This flag is used to decide whether to clear the iOS origin file cache
|
// This flag is used to decide whether to clear the iOS origin file cache
|
||||||
@@ -585,7 +587,7 @@ class FileUploader {
|
|||||||
final encryptedFileExists = File(encryptedFilePath).existsSync();
|
final encryptedFileExists = File(encryptedFilePath).existsSync();
|
||||||
|
|
||||||
// If the multipart entry exists but the encrypted file doesn't, it means
|
// If the multipart entry exists but the encrypted file doesn't, it means
|
||||||
// that we'll have to reupload as the nonce is lost
|
// that we'll have to re-upload as the nonce is lost
|
||||||
if (multipartEntryExists) {
|
if (multipartEntryExists) {
|
||||||
final bool updateWithDiffKey = isUpdatedFile &&
|
final bool updateWithDiffKey = isUpdatedFile &&
|
||||||
multiPartFileEncResult != null &&
|
multiPartFileEncResult != null &&
|
||||||
@@ -623,6 +625,7 @@ class FileUploader {
|
|||||||
} else {
|
} else {
|
||||||
thumbnailData = mediaUploadData.thumbnail;
|
thumbnailData = mediaUploadData.thumbnail;
|
||||||
}
|
}
|
||||||
|
encFileSize = await encryptedFile.length();
|
||||||
|
|
||||||
final EncryptionResult encryptedThumbnailData =
|
final EncryptionResult encryptedThumbnailData =
|
||||||
await CryptoUtil.encryptChaCha(
|
await CryptoUtil.encryptChaCha(
|
||||||
@@ -635,21 +638,24 @@ class FileUploader {
|
|||||||
final encryptedThumbnailFile = File(encryptedThumbnailPath);
|
final encryptedThumbnailFile = File(encryptedThumbnailPath);
|
||||||
await encryptedThumbnailFile
|
await encryptedThumbnailFile
|
||||||
.writeAsBytes(encryptedThumbnailData.encryptedData!);
|
.writeAsBytes(encryptedThumbnailData.encryptedData!);
|
||||||
|
encThumbSize = await encryptedThumbnailFile.length();
|
||||||
|
|
||||||
// Calculate the number of parts for the file.
|
// Calculate the number of parts for the file.
|
||||||
final count = await _multiPartUploader.calculatePartCount(
|
final count = await _multiPartUploader.calculatePartCount(encFileSize);
|
||||||
await encryptedFile.length(),
|
|
||||||
);
|
|
||||||
|
|
||||||
late String fileObjectKey;
|
late String fileObjectKey;
|
||||||
late String thumbnailObjectKey;
|
late String thumbnailObjectKey;
|
||||||
|
|
||||||
if (count <= 1) {
|
if (count <= 1) {
|
||||||
final thumbnailUploadURL = await _getUploadURL();
|
final thumbnailUploadURL = await _getUploadURL();
|
||||||
thumbnailObjectKey =
|
thumbnailObjectKey = await _putFile(
|
||||||
await _putFile(thumbnailUploadURL, encryptedThumbnailFile);
|
thumbnailUploadURL,
|
||||||
|
encryptedThumbnailFile,
|
||||||
|
encThumbSize,
|
||||||
|
);
|
||||||
final fileUploadURL = await _getUploadURL();
|
final fileUploadURL = await _getUploadURL();
|
||||||
fileObjectKey = await _putFile(fileUploadURL, encryptedFile);
|
fileObjectKey =
|
||||||
|
await _putFile(fileUploadURL, encryptedFile, encFileSize);
|
||||||
} else {
|
} else {
|
||||||
isMultipartUpload = true;
|
isMultipartUpload = true;
|
||||||
_logger.finest(
|
_logger.finest(
|
||||||
@@ -672,7 +678,7 @@ class FileUploader {
|
|||||||
collectionID,
|
collectionID,
|
||||||
fileUploadURLs,
|
fileUploadURLs,
|
||||||
encFileName,
|
encFileName,
|
||||||
await encryptedFile.length(),
|
encFileSize,
|
||||||
fileAttributes.key!,
|
fileAttributes.key!,
|
||||||
fileAttributes.header!,
|
fileAttributes.header!,
|
||||||
);
|
);
|
||||||
@@ -686,8 +692,11 @@ class FileUploader {
|
|||||||
// In regular upload, always upload the thumbnail first to keep existing behaviour
|
// In regular upload, always upload the thumbnail first to keep existing behaviour
|
||||||
//
|
//
|
||||||
final thumbnailUploadURL = await _getUploadURL();
|
final thumbnailUploadURL = await _getUploadURL();
|
||||||
thumbnailObjectKey =
|
thumbnailObjectKey = await _putFile(
|
||||||
await _putFile(thumbnailUploadURL, encryptedThumbnailFile);
|
thumbnailUploadURL,
|
||||||
|
encryptedThumbnailFile,
|
||||||
|
encThumbSize,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
final metadata = await file.getMetadataForUpload(mediaUploadData);
|
final metadata = await file.getMetadataForUpload(mediaUploadData);
|
||||||
@@ -713,10 +722,10 @@ class FileUploader {
|
|||||||
file,
|
file,
|
||||||
fileObjectKey,
|
fileObjectKey,
|
||||||
fileDecryptionHeader,
|
fileDecryptionHeader,
|
||||||
await encryptedFile.length(),
|
encFileSize,
|
||||||
thumbnailObjectKey,
|
thumbnailObjectKey,
|
||||||
thumbnailDecryptionHeader,
|
thumbnailDecryptionHeader,
|
||||||
await encryptedThumbnailFile.length(),
|
encThumbSize,
|
||||||
encryptedMetadata,
|
encryptedMetadata,
|
||||||
metadataDecryptionHeader,
|
metadataDecryptionHeader,
|
||||||
);
|
);
|
||||||
@@ -762,10 +771,10 @@ class FileUploader {
|
|||||||
fileAttributes,
|
fileAttributes,
|
||||||
fileObjectKey,
|
fileObjectKey,
|
||||||
fileDecryptionHeader,
|
fileDecryptionHeader,
|
||||||
await encryptedFile.length(),
|
encFileSize,
|
||||||
thumbnailObjectKey,
|
thumbnailObjectKey,
|
||||||
thumbnailDecryptionHeader,
|
thumbnailDecryptionHeader,
|
||||||
await encryptedThumbnailFile.length(),
|
encThumbSize,
|
||||||
encryptedMetadata,
|
encryptedMetadata,
|
||||||
metadataDecryptionHeader,
|
metadataDecryptionHeader,
|
||||||
pubMetadata: pubMetadataRequest,
|
pubMetadata: pubMetadataRequest,
|
||||||
@@ -1266,11 +1275,10 @@ class FileUploader {
|
|||||||
|
|
||||||
Future<String> _putFile(
|
Future<String> _putFile(
|
||||||
UploadURL uploadURL,
|
UploadURL uploadURL,
|
||||||
File file, {
|
File file,
|
||||||
int? contentLength,
|
int fileSize, {
|
||||||
int attempt = 1,
|
int attempt = 1,
|
||||||
}) async {
|
}) async {
|
||||||
final fileSize = contentLength ?? await file.length();
|
|
||||||
_logger.info(
|
_logger.info(
|
||||||
"Putting object for " +
|
"Putting object for " +
|
||||||
file.toString() +
|
file.toString() +
|
||||||
@@ -1304,7 +1312,7 @@ class FileUploader {
|
|||||||
return _putFile(
|
return _putFile(
|
||||||
newUploadURL,
|
newUploadURL,
|
||||||
file,
|
file,
|
||||||
contentLength: fileSize,
|
fileSize,
|
||||||
attempt: attempt + 1,
|
attempt: attempt + 1,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user