Add temporary "upload by hash" for photos.

GitOrigin-RevId: f2fca54bce80d3eb9a84a7f4f6326e98633417a5
This commit is contained in:
levlam 2020-04-24 00:50:14 +03:00
parent 9328c20fcc
commit d26cf8f8a3
2 changed files with 22 additions and 1 deletions

View File

@ -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<FileId> 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<const td_api::inputFileId *>(file.get())->id_, 0);

View File

@ -546,6 +546,8 @@ class FileManager : public FileLoadManager::Callback {
};
Enumerator<RemoteInfo> remote_location_info_;
std::unordered_map<string, FileId> file_hash_to_file_id_;
std::map<FullLocalFileLocation, FileId> local_location_to_file_id_;
std::map<FullGenerateFileLocation, FileId> generate_location_to_file_id_;
std::map<FileDbId, int32> pmc_id_to_file_node_id_;