Add FileManager::is_remotely_generated_file and improve some names.
This commit is contained in:
parent
86acab5250
commit
3a275827e9
|
@ -113,9 +113,9 @@ class FileDownloadGenerateActor final : public FileGenerateActor {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class MapDownloadGenerateActor final : public FileGenerateActor {
|
class WebFileDownloadGenerateActor final : public FileGenerateActor {
|
||||||
public:
|
public:
|
||||||
MapDownloadGenerateActor(string conversion, unique_ptr<FileGenerateCallback> callback, ActorShared<> parent)
|
WebFileDownloadGenerateActor(string conversion, unique_ptr<FileGenerateCallback> callback, ActorShared<> parent)
|
||||||
: conversion_(std::move(conversion)), callback_(std::move(callback)), parent_(std::move(parent)) {
|
: conversion_(std::move(conversion)), callback_(std::move(callback)), parent_(std::move(parent)) {
|
||||||
}
|
}
|
||||||
void file_generate_progress(int64 expected_size, int64 local_prefix_size, Promise<> promise) final {
|
void file_generate_progress(int64 expected_size, int64 local_prefix_size, Promise<> promise) final {
|
||||||
|
@ -132,18 +132,18 @@ class MapDownloadGenerateActor final : public FileGenerateActor {
|
||||||
string file_name_;
|
string file_name_;
|
||||||
|
|
||||||
class Callback final : public NetQueryCallback {
|
class Callback final : public NetQueryCallback {
|
||||||
ActorId<MapDownloadGenerateActor> parent_;
|
ActorId<WebFileDownloadGenerateActor> parent_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Callback(ActorId<MapDownloadGenerateActor> parent) : parent_(parent) {
|
explicit Callback(ActorId<WebFileDownloadGenerateActor> parent) : parent_(parent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void on_result(NetQueryPtr query) final {
|
void on_result(NetQueryPtr query) final {
|
||||||
send_closure(parent_, &MapDownloadGenerateActor::on_result, std::move(query));
|
send_closure(parent_, &WebFileDownloadGenerateActor::on_result, std::move(query));
|
||||||
}
|
}
|
||||||
|
|
||||||
void hangup_shared() final {
|
void hangup_shared() final {
|
||||||
send_closure(parent_, &MapDownloadGenerateActor::hangup_shared);
|
send_closure(parent_, &WebFileDownloadGenerateActor::hangup_shared);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
ActorOwn<NetQueryCallback> net_callback_;
|
ActorOwn<NetQueryCallback> net_callback_;
|
||||||
|
@ -197,7 +197,7 @@ class MapDownloadGenerateActor final : public FileGenerateActor {
|
||||||
return on_error(r_input_web_file.move_as_error());
|
return on_error(r_input_web_file.move_as_error());
|
||||||
}
|
}
|
||||||
|
|
||||||
net_callback_ = create_actor<Callback>("MapDownloadGenerateCallback", actor_id(this));
|
net_callback_ = create_actor<Callback>("WebFileDownloadGenerateCallback", actor_id(this));
|
||||||
|
|
||||||
LOG(INFO) << "Download " << conversion_;
|
LOG(INFO) << "Download " << conversion_;
|
||||||
auto query =
|
auto query =
|
||||||
|
@ -220,7 +220,7 @@ class MapDownloadGenerateActor final : public FileGenerateActor {
|
||||||
TRY_RESULT(web_file, fetch_result<telegram_api::upload_getWebFile>(std::move(query)));
|
TRY_RESULT(web_file, fetch_result<telegram_api::upload_getWebFile>(std::move(query)));
|
||||||
|
|
||||||
if (static_cast<size_t>(web_file->size_) != web_file->bytes_.size()) {
|
if (static_cast<size_t>(web_file->size_) != web_file->bytes_.size()) {
|
||||||
LOG(ERROR) << "Failed to download map of size " << web_file->size_;
|
LOG(ERROR) << "Failed to download web file of size " << web_file->size_;
|
||||||
return Status::Error("File is too big");
|
return Status::Error("File is too big");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -418,9 +418,10 @@ void FileGenerateManager::generate_file(uint64 query_id, FullGenerateFileLocatio
|
||||||
auto file_id = FileId(to_integer<int32>(conversion.substr(file_id_query.size())), 0);
|
auto file_id = FileId(to_integer<int32>(conversion.substr(file_id_query.size())), 0);
|
||||||
query.worker_ = create_actor<FileDownloadGenerateActor>("FileDownloadGenerateActor", generate_location.file_type_,
|
query.worker_ = create_actor<FileDownloadGenerateActor>("FileDownloadGenerateActor", generate_location.file_type_,
|
||||||
file_id, std::move(callback), std::move(parent));
|
file_id, std::move(callback), std::move(parent));
|
||||||
} else if (begins_with(conversion, "#map#") && generate_location.original_path_.empty()) {
|
} else if (FileManager::is_remotely_generated_file(conversion) && generate_location.original_path_.empty()) {
|
||||||
query.worker_ = create_actor<MapDownloadGenerateActor>(
|
query.worker_ = create_actor<WebFileDownloadGenerateActor>("WebFileDownloadGenerateActor",
|
||||||
"MapDownloadGenerateActor", std::move(generate_location.conversion_), std::move(callback), std::move(parent));
|
std::move(generate_location.conversion_),
|
||||||
|
std::move(callback), std::move(parent));
|
||||||
} else {
|
} else {
|
||||||
query.worker_ = create_actor<FileExternalGenerateActor>("FileExternalGenerationActor", query_id, generate_location,
|
query.worker_ = create_actor<FileExternalGenerateActor>("FileExternalGenerationActor", query_id, generate_location,
|
||||||
local_location, std::move(name), std::move(callback),
|
local_location, std::move(name), std::move(callback),
|
||||||
|
|
|
@ -771,7 +771,7 @@ string FileView::get_persistent_id(const FullGenerateFileLocation &location) {
|
||||||
auto binary = serialize(location);
|
auto binary = serialize(location);
|
||||||
|
|
||||||
binary = zero_encode(binary);
|
binary = zero_encode(binary);
|
||||||
binary.push_back(FileNode::PERSISTENT_ID_VERSION_MAP);
|
binary.push_back(FileNode::PERSISTENT_ID_VERSION_GENERATED);
|
||||||
return base64url_encode(binary);
|
return base64url_encode(binary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -790,7 +790,7 @@ string FileView::get_persistent_file_id() const {
|
||||||
return get_persistent_id(remote_location());
|
return get_persistent_id(remote_location());
|
||||||
} else if (has_url()) {
|
} else if (has_url()) {
|
||||||
return url();
|
return url();
|
||||||
} else if (has_generate_location() && begins_with(generate_location().conversion_, "#map#")) {
|
} else if (has_generate_location() && FileManager::is_remotely_generated_file(generate_location().conversion_)) {
|
||||||
return get_persistent_id(generate_location());
|
return get_persistent_id(generate_location());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -803,7 +803,7 @@ string FileView::get_unique_file_id() const {
|
||||||
if (!remote_location().is_web()) {
|
if (!remote_location().is_web()) {
|
||||||
return get_unique_id(remote_location());
|
return get_unique_id(remote_location());
|
||||||
}
|
}
|
||||||
} else if (has_generate_location() && begins_with(generate_location().conversion_, "#map#")) {
|
} else if (has_generate_location() && FileManager::is_remotely_generated_file(generate_location().conversion_)) {
|
||||||
return get_unique_id(generate_location());
|
return get_unique_id(generate_location());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -931,6 +931,10 @@ bool FileManager::are_modification_times_equal(int64 old_mtime, int64 new_mtime)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool FileManager::is_remotely_generated_file(Slice conversion) {
|
||||||
|
return begins_with(conversion, "#map#");
|
||||||
|
}
|
||||||
|
|
||||||
Status FileManager::check_local_location(FullLocalFileLocation &location, int64 &size, bool skip_file_size_checks) {
|
Status FileManager::check_local_location(FullLocalFileLocation &location, int64 &size, bool skip_file_size_checks) {
|
||||||
constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) - 1 /* 200 KB - 1 B */;
|
constexpr int64 MAX_THUMBNAIL_SIZE = 200 * (1 << 10) - 1 /* 200 KB - 1 B */;
|
||||||
constexpr int64 MAX_PHOTO_SIZE = 10 * (1 << 20) /* 10 MB */;
|
constexpr int64 MAX_PHOTO_SIZE = 10 * (1 << 20) /* 10 MB */;
|
||||||
|
@ -2917,13 +2921,13 @@ Result<FileId> FileManager::from_persistent_id(CSlice persistent_id, FileType fi
|
||||||
if (binary.back() == FileNode::PERSISTENT_ID_VERSION) {
|
if (binary.back() == FileNode::PERSISTENT_ID_VERSION) {
|
||||||
return from_persistent_id_v3(binary, file_type);
|
return from_persistent_id_v3(binary, file_type);
|
||||||
}
|
}
|
||||||
if (binary.back() == FileNode::PERSISTENT_ID_VERSION_MAP) {
|
if (binary.back() == FileNode::PERSISTENT_ID_VERSION_GENERATED) {
|
||||||
return from_persistent_id_map(binary, file_type);
|
return from_persistent_id_generated(binary, file_type);
|
||||||
}
|
}
|
||||||
return Status::Error(400, "Wrong remote file identifier specified: can't unserialize it. Wrong last symbol");
|
return Status::Error(400, "Wrong remote file identifier specified: can't unserialize it. Wrong last symbol");
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<FileId> FileManager::from_persistent_id_map(Slice binary, FileType file_type) {
|
Result<FileId> FileManager::from_persistent_id_generated(Slice binary, FileType file_type) {
|
||||||
binary.remove_suffix(1);
|
binary.remove_suffix(1);
|
||||||
auto decoded_binary = zero_decode(binary);
|
auto decoded_binary = zero_decode(binary);
|
||||||
FullGenerateFileLocation generate_location;
|
FullGenerateFileLocation generate_location;
|
||||||
|
@ -2936,12 +2940,13 @@ Result<FileId> FileManager::from_persistent_id_map(Slice binary, FileType file_t
|
||||||
(real_file_type != FileType::Thumbnail && real_file_type != FileType::EncryptedThumbnail)) {
|
(real_file_type != FileType::Thumbnail && real_file_type != FileType::EncryptedThumbnail)) {
|
||||||
return Status::Error(400, "Type of file mismatch");
|
return Status::Error(400, "Type of file mismatch");
|
||||||
}
|
}
|
||||||
if (!begins_with(generate_location.conversion_, "#map#")) {
|
if (!is_remotely_generated_file(generate_location.conversion_)) {
|
||||||
return Status::Error(400, "Unexpected conversion type");
|
return Status::Error(400, "Unexpected conversion type");
|
||||||
}
|
}
|
||||||
FileData data;
|
FileData data;
|
||||||
data.generate_ = make_unique<FullGenerateFileLocation>(std::move(generate_location));
|
data.generate_ = make_unique<FullGenerateFileLocation>(std::move(generate_location));
|
||||||
return register_file(std::move(data), FileLocationSource::FromUser, "from_persistent_id_map", false).move_as_ok();
|
return register_file(std::move(data), FileLocationSource::FromUser, "from_persistent_id_generated", false)
|
||||||
|
.move_as_ok();
|
||||||
}
|
}
|
||||||
|
|
||||||
Result<FileId> FileManager::from_persistent_id_v23(Slice binary, FileType file_type, int32 version) {
|
Result<FileId> FileManager::from_persistent_id_v23(Slice binary, FileType file_type, int32 version) {
|
||||||
|
|
|
@ -126,7 +126,7 @@ class FileNode {
|
||||||
friend class FileManager;
|
friend class FileManager;
|
||||||
|
|
||||||
static constexpr char PERSISTENT_ID_VERSION_OLD = 2;
|
static constexpr char PERSISTENT_ID_VERSION_OLD = 2;
|
||||||
static constexpr char PERSISTENT_ID_VERSION_MAP = 3;
|
static constexpr char PERSISTENT_ID_VERSION_GENERATED = 3;
|
||||||
static constexpr char PERSISTENT_ID_VERSION = 4;
|
static constexpr char PERSISTENT_ID_VERSION = 4;
|
||||||
|
|
||||||
LocalFileLocation local_;
|
LocalFileLocation local_;
|
||||||
|
@ -417,6 +417,8 @@ class FileManager final : public FileLoadManager::Callback {
|
||||||
|
|
||||||
static bool are_modification_times_equal(int64 old_mtime, int64 new_mtime);
|
static bool are_modification_times_equal(int64 old_mtime, int64 new_mtime);
|
||||||
|
|
||||||
|
static bool is_remotely_generated_file(Slice conversion);
|
||||||
|
|
||||||
void init_actor();
|
void init_actor();
|
||||||
|
|
||||||
FileId dup_file_id(FileId file_id);
|
FileId dup_file_id(FileId file_id);
|
||||||
|
@ -620,7 +622,7 @@ class FileManager final : public FileLoadManager::Callback {
|
||||||
void flush_to_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate, const char *source);
|
void flush_to_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate, const char *source);
|
||||||
void load_from_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate);
|
void load_from_pmc(FileNodePtr node, bool new_remote, bool new_local, bool new_generate);
|
||||||
|
|
||||||
Result<FileId> from_persistent_id_map(Slice binary, FileType file_type);
|
Result<FileId> from_persistent_id_generated(Slice binary, FileType file_type);
|
||||||
Result<FileId> from_persistent_id_v2(Slice binary, FileType file_type);
|
Result<FileId> from_persistent_id_v2(Slice binary, FileType file_type);
|
||||||
Result<FileId> from_persistent_id_v3(Slice binary, FileType file_type);
|
Result<FileId> from_persistent_id_v3(Slice binary, FileType file_type);
|
||||||
Result<FileId> from_persistent_id_v23(Slice binary, FileType file_type, int32 version);
|
Result<FileId> from_persistent_id_v23(Slice binary, FileType file_type, int32 version);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user