diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index 777f7f240..a0ed6213a 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -25,6 +25,7 @@ #include "td/actor/SleepActor.h" #include "td/utils/base64.h" +#include "td/utils/filesystem.h" #include "td/utils/format.h" #include "td/utils/HttpUrl.h" #include "td/utils/logging.h" @@ -3025,7 +3026,25 @@ Result FileManager::get_input_file_id(FileType type, const tl_object_ptr if (allow_zero && path.empty()) { return FileId(); } - return register_local(FullLocalFileLocation(new_type, path, 0), owner_dialog_id, 0, get_by_hash); + string hash; + if (false && new_type == FileType::Photo) { + auto r_stat = stat(path); + if (r_stat.is_ok() && r_stat.ok().size_ > 0 && r_stat.ok().size_ < 1000000) { + auto r_file_content = read_file_str(path, r_stat.ok().size_); + if (r_file_content.is_ok()) { + hash = sha256(r_file_content.ok()); + auto it = file_hash_to_file_id_.find(hash); + if (it != file_hash_to_file_id_.end()) { + return it->second; + } + } + } + } + TRY_RESULT(file_id, register_local(FullLocalFileLocation(new_type, path, 0), owner_dialog_id, 0, get_by_hash)); + if (!hash.empty()) { + file_hash_to_file_id_[hash] = file_id; + } + return file_id; } case td_api::inputFileId::ID: { FileId file_id(static_cast(file.get())->id_, 0); diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index d6da57540..fe9a859db 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -546,6 +546,8 @@ class FileManager : public FileLoadManager::Callback { }; Enumerator remote_location_info_; + std::unordered_map file_hash_to_file_id_; + std::map local_location_to_file_id_; std::map generate_location_to_file_id_; std::map pmc_id_to_file_node_id_;