Better FileLocationSource.
GitOrigin-RevId: bed0d4f52b129560097f0877bd4b3d3511914f27
This commit is contained in:
parent
e66cc39f95
commit
f0e660e2aa
@ -222,9 +222,9 @@ std::pair<DocumentsManager::DocumentType, FileId> DocumentsManager::on_get_docum
|
|||||||
file_name += extension;
|
file_name += extension;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FileId file_id =
|
FileId file_id = td_->file_manager_->register_remote(
|
||||||
td_->file_manager_->register_remote(FullRemoteFileLocation(file_type, id, access_hash, DcId::internal(dc_id)),
|
FullRemoteFileLocation(file_type, id, access_hash, DcId::internal(dc_id)), FileLocationSource::FromServer,
|
||||||
owner_dialog_id, size, 0, suggested_file_name);
|
owner_dialog_id, size, 0, suggested_file_name);
|
||||||
if (!encryption_key.empty()) {
|
if (!encryption_key.empty()) {
|
||||||
td_->file_manager_->set_encryption_key(file_id, std::move(encryption_key));
|
td_->file_manager_->set_encryption_key(file_id, std::move(encryption_key));
|
||||||
}
|
}
|
||||||
|
@ -8759,7 +8759,7 @@ void MessagesManager::on_send_secret_message_success(int64 random_id, MessageId
|
|||||||
|
|
||||||
new_file_id = td_->file_manager_->register_remote(
|
new_file_id = td_->file_manager_->register_remote(
|
||||||
FullRemoteFileLocation(FileType::Encrypted, file->id_, file->access_hash_, DcId::internal(file->dc_id_)),
|
FullRemoteFileLocation(FileType::Encrypted, file->id_, file->access_hash_, DcId::internal(file->dc_id_)),
|
||||||
owner_dialog_id, 0, 0);
|
FileLocationSource::FromServer, owner_dialog_id, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -19963,7 +19963,7 @@ Photo MessagesManager::get_web_document_photo(tl_object_ptr<telegram_api::webDoc
|
|||||||
// TODO real file name
|
// TODO real file name
|
||||||
FileId file_id = td_->file_manager_->register_remote(
|
FileId file_id = td_->file_manager_->register_remote(
|
||||||
FullRemoteFileLocation(FileType::Photo, url, web_document->access_hash_, DcId::internal(web_document->dc_id_)),
|
FullRemoteFileLocation(FileType::Photo, url, web_document->access_hash_, DcId::internal(web_document->dc_id_)),
|
||||||
owner_dialog_id, 0, web_document->size_, "");
|
FileLocationSource::FromServer, owner_dialog_id, 0, web_document->size_, "");
|
||||||
|
|
||||||
Dimensions dimensions;
|
Dimensions dimensions;
|
||||||
for (auto &attribute : web_document->attributes_) {
|
for (auto &attribute : web_document->attributes_) {
|
||||||
@ -20360,8 +20360,8 @@ unique_ptr<MessageContent> MessagesManager::dup_message_content(DialogId dialog_
|
|||||||
if (to_secret && !file_view.is_encrypted()) {
|
if (to_secret && !file_view.is_encrypted()) {
|
||||||
auto download_file_id = file_manager->dup_file_id(file_id);
|
auto download_file_id = file_manager->dup_file_id(file_id);
|
||||||
file_id = file_manager
|
file_id = file_manager
|
||||||
->register_generate(FileType::Encrypted, "", PSTRING() << "#file_id#" << download_file_id.get(),
|
->register_generate(FileType::Encrypted, FileLocationSource::FromServer, "",
|
||||||
dialog_id, file_view.size())
|
PSTRING() << "#file_id#" << download_file_id.get(), dialog_id, file_view.size())
|
||||||
.ok();
|
.ok();
|
||||||
}
|
}
|
||||||
return file_manager->dup_file_id(file_id);
|
return file_manager->dup_file_id(file_id);
|
||||||
@ -21945,7 +21945,7 @@ bool MessagesManager::update_message_content(DialogId dialog_id, const Message *
|
|||||||
FileId file_id = td_->file_manager_->register_remote(
|
FileId file_id = td_->file_manager_->register_remote(
|
||||||
FullRemoteFileLocation(FileType::Photo, new_file_view.remote_location().get_id(),
|
FullRemoteFileLocation(FileType::Photo, new_file_view.remote_location().get_id(),
|
||||||
new_file_view.remote_location().get_access_hash(), 0, 0, 0, DcId::invalid()),
|
new_file_view.remote_location().get_access_hash(), 0, 0, 0, DcId::invalid()),
|
||||||
dialog_id, old_photo->photos.back().size, 0, "");
|
FileLocationSource::FromServer, dialog_id, old_photo->photos.back().size, 0, "");
|
||||||
LOG_STATUS(td_->file_manager_->merge(file_id, old_file_id));
|
LOG_STATUS(td_->file_manager_->merge(file_id, old_file_id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,8 +92,8 @@ static FileId register_photo(FileManager *file_manager, FileType file_type, int6
|
|||||||
LOG(DEBUG) << "Receive photo of type " << static_cast<int8>(file_type) << " in [" << dc_id << "," << volume_id << ","
|
LOG(DEBUG) << "Receive photo of type " << static_cast<int8>(file_type) << " in [" << dc_id << "," << volume_id << ","
|
||||||
<< local_id << "]. Id: (" << id << ", " << access_hash << ")";
|
<< local_id << "]. Id: (" << id << ", " << access_hash << ")";
|
||||||
return file_manager->register_remote(
|
return file_manager->register_remote(
|
||||||
FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret, dc_id), owner_dialog_id,
|
FullRemoteFileLocation(file_type, id, access_hash, local_id, volume_id, secret, dc_id),
|
||||||
file_size, 0, to_string(std::abs(id ? id : local_id)) + ".jpg");
|
FileLocationSource::FromServer, owner_dialog_id, file_size, 0, to_string(std::abs(id ? id : local_id)) + ".jpg");
|
||||||
}
|
}
|
||||||
|
|
||||||
ProfilePhoto get_profile_photo(FileManager *file_manager,
|
ProfilePhoto get_profile_photo(FileManager *file_manager,
|
||||||
@ -221,8 +221,8 @@ PhotoSize get_thumbnail_photo_size(FileManager *file_manager, BufferSlice bytes,
|
|||||||
auto volume_id = Random::secure_int64();
|
auto volume_id = Random::secure_int64();
|
||||||
auto secret = 0;
|
auto secret = 0;
|
||||||
res.file_id = file_manager->register_remote(
|
res.file_id = file_manager->register_remote(
|
||||||
FullRemoteFileLocation(FileType::EncryptedThumbnail, 0, 0, local_id, volume_id, secret, dc_id), owner_dialog_id,
|
FullRemoteFileLocation(FileType::EncryptedThumbnail, 0, 0, local_id, volume_id, secret, dc_id),
|
||||||
res.size, 0, to_string(std::abs(local_id)) + ".jpg");
|
FileLocationSource::FromServer, owner_dialog_id, res.size, 0, to_string(std::abs(local_id)) + ".jpg");
|
||||||
file_manager->set_content(res.file_id, std::move(bytes));
|
file_manager->set_content(res.file_id, std::move(bytes));
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@ -315,7 +315,7 @@ Photo get_photo(FileManager *file_manager, tl_object_ptr<telegram_api::encrypted
|
|||||||
CHECK(DcId::is_valid(file->dc_id_));
|
CHECK(DcId::is_valid(file->dc_id_));
|
||||||
FileId file_id = file_manager->register_remote(
|
FileId file_id = file_manager->register_remote(
|
||||||
FullRemoteFileLocation(FileType::Encrypted, file->id_, file->access_hash_, DcId::internal(file->dc_id_)),
|
FullRemoteFileLocation(FileType::Encrypted, file->id_, file->access_hash_, DcId::internal(file->dc_id_)),
|
||||||
owner_dialog_id, photo->size_, 0, to_string(std::abs(file->id_)) + ".jpg");
|
FileLocationSource::FromServer, owner_dialog_id, photo->size_, 0, to_string(std::abs(file->id_)) + ".jpg");
|
||||||
file_manager->set_encryption_key(file_id, FileEncryptionKey{photo->key_.as_slice(), photo->iv_.as_slice()});
|
file_manager->set_encryption_key(file_id, FileEncryptionKey{photo->key_.as_slice(), photo->iv_.as_slice()});
|
||||||
|
|
||||||
Photo res;
|
Photo res;
|
||||||
|
@ -955,7 +955,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(tl_object_ptr<
|
|||||||
int64 document_id = document->id_;
|
int64 document_id = document->id_;
|
||||||
FileId sticker_id = td_->file_manager_->register_remote(
|
FileId sticker_id = td_->file_manager_->register_remote(
|
||||||
FullRemoteFileLocation(FileType::Sticker, document_id, document->access_hash_, DcId::internal(document->dc_id_)),
|
FullRemoteFileLocation(FileType::Sticker, document_id, document->access_hash_, DcId::internal(document->dc_id_)),
|
||||||
DialogId(), document->size_, 0, to_string(document_id) + ".webp");
|
FileLocationSource::FromServer, DialogId(), document->size_, 0, to_string(document_id) + ".webp");
|
||||||
|
|
||||||
PhotoSize thumbnail =
|
PhotoSize thumbnail =
|
||||||
get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, DialogId(), std::move(document->thumb_));
|
get_photo_size(td_->file_manager_.get(), FileType::Thumbnail, 0, 0, DialogId(), std::move(document->thumb_));
|
||||||
|
@ -593,32 +593,34 @@ Result<FileId> FileManager::register_local(FullLocalFileLocation location, Dialo
|
|||||||
return register_file(std::move(data), FileLocationSource::None /*won't be used*/, "register_local", force);
|
return register_file(std::move(data), FileLocationSource::None /*won't be used*/, "register_local", force);
|
||||||
}
|
}
|
||||||
|
|
||||||
FileId FileManager::register_remote(const FullRemoteFileLocation &location, DialogId owner_dialog_id, int64 size,
|
FileId FileManager::register_remote(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
|
||||||
int64 expected_size, string name) {
|
DialogId owner_dialog_id, int64 size, int64 expected_size, string name) {
|
||||||
FileData data;
|
FileData data;
|
||||||
data.remote_ = RemoteFileLocation(location);
|
data.remote_ = RemoteFileLocation(location);
|
||||||
data.owner_dialog_id_ = owner_dialog_id;
|
data.owner_dialog_id_ = owner_dialog_id;
|
||||||
data.size_ = size;
|
data.size_ = size;
|
||||||
data.expected_size_ = expected_size;
|
data.expected_size_ = expected_size;
|
||||||
data.name_ = std::move(name);
|
data.name_ = std::move(name);
|
||||||
return register_file(std::move(data), FileLocationSource::FromServer, "register_remote", false).move_as_ok();
|
return register_file(std::move(data), file_location_source, "register_remote", false).move_as_ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
FileId FileManager::register_url(string url, FileType file_type, DialogId owner_dialog_id) {
|
FileId FileManager::register_url(string url, FileType file_type, FileLocationSource file_location_source,
|
||||||
auto file_id = register_generate(file_type, url, "#url#", owner_dialog_id, 0).ok();
|
DialogId owner_dialog_id) {
|
||||||
|
auto file_id = register_generate(file_type, file_location_source, url, "#url#", owner_dialog_id, 0).ok();
|
||||||
auto *file_node = get_file_node(file_id);
|
auto *file_node = get_file_node(file_id);
|
||||||
CHECK(file_node);
|
CHECK(file_node);
|
||||||
file_node->set_url(url);
|
file_node->set_url(url);
|
||||||
return file_id;
|
return file_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<FileId> FileManager::register_generate(FileType file_type, string original_path, string conversion,
|
Result<FileId> FileManager::register_generate(FileType file_type, FileLocationSource file_location_source,
|
||||||
DialogId owner_dialog_id, int64 expected_size) {
|
string original_path, string conversion, DialogId owner_dialog_id,
|
||||||
|
int64 expected_size) {
|
||||||
FileData data;
|
FileData data;
|
||||||
data.generate_ = GenerateFileLocation(FullGenerateFileLocation(file_type, original_path, std::move(conversion)));
|
data.generate_ = GenerateFileLocation(FullGenerateFileLocation(file_type, original_path, std::move(conversion)));
|
||||||
data.owner_dialog_id_ = owner_dialog_id;
|
data.owner_dialog_id_ = owner_dialog_id;
|
||||||
data.expected_size_ = expected_size;
|
data.expected_size_ = expected_size;
|
||||||
return register_file(std::move(data), FileLocationSource::FromServer, "register_generate", false);
|
return register_file(std::move(data), file_location_source, "register_generate", false);
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<FileId> FileManager::register_file(FileData data, FileLocationSource file_location_source, const char *source,
|
Result<FileId> FileManager::register_file(FileData data, FileLocationSource file_location_source, const char *source,
|
||||||
@ -1705,7 +1707,7 @@ Result<FileId> FileManager::from_persistent_id(CSlice persistent_id, FileType fi
|
|||||||
if (!clean_input_string(url)) {
|
if (!clean_input_string(url)) {
|
||||||
return Status::Error(400, "URL must be in UTF-8");
|
return Status::Error(400, "URL must be in UTF-8");
|
||||||
}
|
}
|
||||||
return register_url(std::move(url), file_type, DialogId());
|
return register_url(std::move(url), file_type, FileLocationSource::FromUser, DialogId());
|
||||||
}
|
}
|
||||||
|
|
||||||
auto r_binary = base64url_decode(persistent_id);
|
auto r_binary = base64url_decode(persistent_id);
|
||||||
@ -1851,8 +1853,8 @@ Result<FileId> FileManager::get_input_thumbnail_file_id(const tl_object_ptr<td_a
|
|||||||
case td_api::inputFileGenerated::ID: {
|
case td_api::inputFileGenerated::ID: {
|
||||||
auto *generated_thumbnail = static_cast<const td_api::inputFileGenerated *>(thumbnail_input_file.get());
|
auto *generated_thumbnail = static_cast<const td_api::inputFileGenerated *>(thumbnail_input_file.get());
|
||||||
return register_generate(is_encrypted ? FileType::EncryptedThumbnail : FileType::Thumbnail,
|
return register_generate(is_encrypted ? FileType::EncryptedThumbnail : FileType::Thumbnail,
|
||||||
generated_thumbnail->original_path_, generated_thumbnail->conversion_, owner_dialog_id,
|
FileLocationSource::FromUser, generated_thumbnail->original_path_,
|
||||||
generated_thumbnail->expected_size_);
|
generated_thumbnail->conversion_, owner_dialog_id, generated_thumbnail->expected_size_);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -1899,8 +1901,9 @@ Result<FileId> FileManager::get_input_file_id(FileType type, const tl_object_ptr
|
|||||||
}
|
}
|
||||||
case td_api::inputFileGenerated::ID: {
|
case td_api::inputFileGenerated::ID: {
|
||||||
auto *generated_file = static_cast<const td_api::inputFileGenerated *>(file.get());
|
auto *generated_file = static_cast<const td_api::inputFileGenerated *>(file.get());
|
||||||
return register_generate(is_encrypted ? FileType::Encrypted : type, generated_file->original_path_,
|
return register_generate(is_encrypted ? FileType::Encrypted : type, FileLocationSource::FromUser,
|
||||||
generated_file->conversion_, owner_dialog_id, generated_file->expected_size_);
|
generated_file->original_path_, generated_file->conversion_, owner_dialog_id,
|
||||||
|
generated_file->expected_size_);
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
UNREACHABLE();
|
UNREACHABLE();
|
||||||
@ -2070,7 +2073,7 @@ void FileManager::on_upload_ok(QueryId query_id, FileType file_type, const Parti
|
|||||||
void FileManager::on_upload_full_ok(QueryId query_id, const FullRemoteFileLocation &remote) {
|
void FileManager::on_upload_full_ok(QueryId query_id, const FullRemoteFileLocation &remote) {
|
||||||
LOG(INFO) << "ON UPLOAD OK";
|
LOG(INFO) << "ON UPLOAD OK";
|
||||||
auto file_id = finish_query(query_id).first.file_id_;
|
auto file_id = finish_query(query_id).first.file_id_;
|
||||||
auto new_file_id = register_remote(remote, DialogId(), 0, 0, "");
|
auto new_file_id = register_remote(remote, FileLocationSource::FromServer, DialogId(), 0, 0, "");
|
||||||
LOG_STATUS(merge(new_file_id, file_id));
|
LOG_STATUS(merge(new_file_id, file_id));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -246,10 +246,12 @@ class FileManager : public FileLoadManager::Callback {
|
|||||||
FileId register_empty(FileType type);
|
FileId register_empty(FileType type);
|
||||||
Result<FileId> register_local(FullLocalFileLocation location, DialogId owner_dialog_id, int64 size,
|
Result<FileId> register_local(FullLocalFileLocation location, DialogId owner_dialog_id, int64 size,
|
||||||
bool get_by_hash = false, bool force = false) TD_WARN_UNUSED_RESULT;
|
bool get_by_hash = false, bool force = false) TD_WARN_UNUSED_RESULT;
|
||||||
FileId register_remote(const FullRemoteFileLocation &location, DialogId owner_dialog_id, int64 size,
|
FileId register_remote(const FullRemoteFileLocation &location, FileLocationSource file_location_source,
|
||||||
int64 expected_size, string name = "") TD_WARN_UNUSED_RESULT;
|
DialogId owner_dialog_id, int64 size, int64 expected_size,
|
||||||
Result<FileId> register_generate(FileType file_type, string original_path, string conversion,
|
string name = "") TD_WARN_UNUSED_RESULT;
|
||||||
DialogId owner_dialog_id, int64 expected_size) TD_WARN_UNUSED_RESULT;
|
Result<FileId> register_generate(FileType file_type, FileLocationSource file_location_source, string original_path,
|
||||||
|
string conversion, DialogId owner_dialog_id,
|
||||||
|
int64 expected_size) TD_WARN_UNUSED_RESULT;
|
||||||
Result<FileId> register_file(FileData data, FileLocationSource file_location_source, const char *source, bool force);
|
Result<FileId> register_file(FileData data, FileLocationSource file_location_source, const char *source, bool force);
|
||||||
|
|
||||||
Result<FileId> merge(FileId x_file_id, FileId y_file_id, bool no_sync = false) TD_WARN_UNUSED_RESULT;
|
Result<FileId> merge(FileId x_file_id, FileId y_file_id, bool no_sync = false) TD_WARN_UNUSED_RESULT;
|
||||||
@ -294,7 +296,8 @@ class FileManager : public FileLoadManager::Callback {
|
|||||||
Result<FileId> check_input_file_id(FileType type, Result<FileId> result, bool is_encrypted,
|
Result<FileId> check_input_file_id(FileType type, Result<FileId> result, bool is_encrypted,
|
||||||
bool allow_zero) TD_WARN_UNUSED_RESULT;
|
bool allow_zero) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
FileId register_url(string url, FileType file_type, DialogId owner_dialog_id);
|
FileId register_url(string url, FileType file_type, FileLocationSource file_location_source,
|
||||||
|
DialogId owner_dialog_id);
|
||||||
|
|
||||||
static constexpr int8 FROM_BYTES_PRIORITY = 10;
|
static constexpr int8 FROM_BYTES_PRIORITY = 10;
|
||||||
using FileNodeId = int32;
|
using FileNodeId = int32;
|
||||||
|
@ -142,7 +142,8 @@ FileId FileManager::parse_file(ParserT &parser) {
|
|||||||
if (parser.version() >= static_cast<int32>(Version::StoreFileOwnerId)) {
|
if (parser.version() >= static_cast<int32>(Version::StoreFileOwnerId)) {
|
||||||
parse(owner_dialog_id, parser);
|
parse(owner_dialog_id, parser);
|
||||||
}
|
}
|
||||||
return register_remote(full_remote_location, owner_dialog_id, size, expected_size, name);
|
return register_remote(full_remote_location, FileLocationSource::FromDb, owner_dialog_id, size, expected_size,
|
||||||
|
name);
|
||||||
}
|
}
|
||||||
case FileStoreType::Local: {
|
case FileStoreType::Local: {
|
||||||
FullLocalFileLocation full_local_location;
|
FullLocalFileLocation full_local_location;
|
||||||
@ -186,8 +187,9 @@ FileId FileManager::parse_file(ParserT &parser) {
|
|||||||
full_generated_location.conversion_ = PSTRING() << "#file_id#" << download_file_id.get();
|
full_generated_location.conversion_ = PSTRING() << "#file_id#" << download_file_id.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
auto r_file_id = register_generate(full_generated_location.file_type_, full_generated_location.original_path_,
|
auto r_file_id = register_generate(full_generated_location.file_type_, FileLocationSource::FromDb,
|
||||||
full_generated_location.conversion_, owner_dialog_id, expected_size);
|
full_generated_location.original_path_, full_generated_location.conversion_,
|
||||||
|
owner_dialog_id, expected_size);
|
||||||
if (r_file_id.is_ok()) {
|
if (r_file_id.is_ok()) {
|
||||||
return r_file_id.move_as_ok();
|
return r_file_id.move_as_ok();
|
||||||
}
|
}
|
||||||
@ -202,7 +204,7 @@ FileId FileManager::parse_file(ParserT &parser) {
|
|||||||
if (parser.version() >= static_cast<int32>(Version::StoreFileOwnerId)) {
|
if (parser.version() >= static_cast<int32>(Version::StoreFileOwnerId)) {
|
||||||
parse(owner_dialog_id, parser);
|
parse(owner_dialog_id, parser);
|
||||||
}
|
}
|
||||||
return register_url(url, type, owner_dialog_id);
|
return register_url(url, type, FileLocationSource::FromDb, owner_dialog_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return FileId();
|
return FileId();
|
||||||
|
Reference in New Issue
Block a user