From 274e00175ec7ae25be63212c18e6222543945912 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 27 Dec 2018 18:09:09 +0300 Subject: [PATCH] Add is_file_big function. GitOrigin-RevId: 54b5c7eb69a005d138afbdbca8587afa3c6541cf --- td/telegram/files/FileLocation.h | 17 +++++++++++++++-- td/telegram/files/FileManager.cpp | 10 +++++----- td/telegram/files/FileUploader.cpp | 2 +- 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/td/telegram/files/FileLocation.h b/td/telegram/files/FileLocation.h index 1c78a61d..eb2c2100 100644 --- a/td/telegram/files/FileLocation.h +++ b/td/telegram/files/FileLocation.h @@ -33,8 +33,6 @@ namespace td { -constexpr int64 SMALL_FILE_MAX_SIZE = 10 * (1 << 20); - enum class FileType : int8 { Thumbnail, ProfilePhoto, @@ -165,6 +163,21 @@ inline FileDirType get_file_dir_type(FileType file_type) { } } +inline bool is_file_big(FileType file_type, int64 expected_size) { + switch (file_type) { + case FileType::Thumbnail: + case FileType::ProfilePhoto: + case FileType::Photo: + case FileType::EncryptedThumbnail: + return false; + default: + break; + } + + constexpr int64 SMALL_FILE_MAX_SIZE = 10 << 20; + return expected_size > SMALL_FILE_MAX_SIZE; +} + struct FileEncryptionKey { enum class Type : int32 { None, Secret, Secure }; FileEncryptionKey() = default; diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 115cbb01..d0413e99 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -2588,8 +2588,9 @@ void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type, if (status.message() == "FILE_PART_INVALID") { bool has_partial_small_location = node->remote_.type() == RemoteFileLocation::Type::Partial && !node->remote_.partial().is_big_; - auto expected_size = FileView(node).expected_size(true); - bool should_be_big_location = expected_size > SMALL_FILE_MAX_SIZE; + FileView file_view(node); + auto expected_size = file_view.expected_size(true); + bool should_be_big_location = is_file_big(file_view.get_type(), expected_size); node->set_remote_location(RemoteFileLocation(), FileLocationSource::None, 0); if (has_partial_small_location && should_be_big_location) { @@ -2597,9 +2598,8 @@ void FileManager::on_error_impl(FileNodePtr node, FileManager::Query::Type type, return; } - LOG(WARNING) << "Failed to upload file: unexpected " << status << " " << has_partial_small_location << " " - << should_be_big_location << " " - << "expected size: " << expected_size; + LOG(WARNING) << "Failed to upload file: unexpected " << status << ", is_small = " << has_partial_small_location + << ", should_be_big = " << should_be_big_location << ", expected size = " << expected_size; } if (begins_with(status.message(), "FILE_GENERATE_LOCATION_INVALID")) { diff --git a/td/telegram/files/FileUploader.cpp b/td/telegram/files/FileUploader.cpp index 486a1c43..3894e751 100644 --- a/td/telegram/files/FileUploader.cpp +++ b/td/telegram/files/FileUploader.cpp @@ -61,7 +61,7 @@ Result FileUploader::init() { offset = partial.ready_part_count_; } else { file_id_ = Random::secure_int64(); - big_flag_ = expected_size_ > SMALL_FILE_MAX_SIZE; + big_flag_ = is_file_big(file_type_, expected_size_); } std::vector ok(offset, true);