Pass promise to FileManager::download.
This commit is contained in:
parent
3648df4e0d
commit
188a7b7c3e
@ -47,12 +47,14 @@ void DownloadManagerCallback::update_file_removed(FileId file_id, DownloadManage
|
|||||||
void DownloadManagerCallback::start_file(FileId file_id, int8 priority, ActorShared<DownloadManager> download_manager) {
|
void DownloadManagerCallback::start_file(FileId file_id, int8 priority, ActorShared<DownloadManager> download_manager) {
|
||||||
send_closure_later(td_->file_manager_actor_, &FileManager::download, file_id,
|
send_closure_later(td_->file_manager_actor_, &FileManager::download, file_id,
|
||||||
make_download_file_callback(td_, std::move(download_manager)), priority,
|
make_download_file_callback(td_, std::move(download_manager)), priority,
|
||||||
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::IGNORE_DOWNLOAD_LIMIT);
|
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::IGNORE_DOWNLOAD_LIMIT,
|
||||||
|
Promise<td_api::object_ptr<td_api::file>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadManagerCallback::pause_file(FileId file_id) {
|
void DownloadManagerCallback::pause_file(FileId file_id) {
|
||||||
send_closure_later(td_->file_manager_actor_, &FileManager::download, file_id, nullptr, 0,
|
send_closure_later(td_->file_manager_actor_, &FileManager::download, file_id, nullptr, 0,
|
||||||
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::KEEP_DOWNLOAD_LIMIT);
|
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::KEEP_DOWNLOAD_LIMIT,
|
||||||
|
Promise<td_api::object_ptr<td_api::file>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void DownloadManagerCallback::delete_file(FileId file_id) {
|
void DownloadManagerCallback::delete_file(FileId file_id) {
|
||||||
|
@ -9032,7 +9032,8 @@ void MessagesManager::load_secret_thumbnail(FileId thumbnail_file_id) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
send_closure(G()->file_manager(), &FileManager::download, thumbnail_file_id,
|
send_closure(G()->file_manager(), &FileManager::download, thumbnail_file_id,
|
||||||
std::make_shared<Callback>(std::move(download_promise)), 1, -1, -1);
|
std::make_shared<Callback>(std::move(download_promise)), 1, -1, -1,
|
||||||
|
Promise<td_api::object_ptr<td_api::file>>());
|
||||||
}
|
}
|
||||||
|
|
||||||
void MessagesManager::on_upload_media(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file,
|
void MessagesManager::on_upload_media(FileId file_id, tl_object_ptr<telegram_api::InputFile> input_file,
|
||||||
|
@ -6406,11 +6406,12 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) {
|
|||||||
DownloadInfo *info = info_it == pending_file_downloads_.end() ? nullptr : &info_it->second;
|
DownloadInfo *info = info_it == pending_file_downloads_.end() ? nullptr : &info_it->second;
|
||||||
if (info != nullptr && (offset != info->offset || limit != info->limit)) {
|
if (info != nullptr && (offset != info->offset || limit != info->limit)) {
|
||||||
// we can't have two pending requests with different offset and limit, so cancel all previous requests
|
// we can't have two pending requests with different offset and limit, so cancel all previous requests
|
||||||
for (auto request_id : info->request_ids) {
|
auto request_ids = std::move(info->request_ids);
|
||||||
|
info->request_ids.clear();
|
||||||
|
for (auto request_id : request_ids) {
|
||||||
send_closure(actor_id(this), &Td::send_error, request_id,
|
send_closure(actor_id(this), &Td::send_error, request_id,
|
||||||
Status::Error(200, "Canceled by another downloadFile request"));
|
Status::Error(200, "Canceled by another downloadFile request"));
|
||||||
}
|
}
|
||||||
info->request_ids.clear();
|
|
||||||
}
|
}
|
||||||
if (request.synchronous_) {
|
if (request.synchronous_) {
|
||||||
if (info == nullptr) {
|
if (info == nullptr) {
|
||||||
@ -6420,10 +6421,12 @@ void Td::on_request(uint64 id, const td_api::downloadFile &request) {
|
|||||||
info->limit = limit;
|
info->limit = limit;
|
||||||
info->request_ids.push_back(id);
|
info->request_ids.push_back(id);
|
||||||
}
|
}
|
||||||
file_manager_->download(file_id, download_file_callback_, priority, offset, limit);
|
Promise<td_api::object_ptr<td_api::file>> download_promise;
|
||||||
if (!request.synchronous_) {
|
if (!request.synchronous_) {
|
||||||
send_closure(actor_id(this), &Td::send_result, id, file_manager_->get_file_object(file_id, false));
|
CREATE_REQUEST_PROMISE();
|
||||||
|
download_promise = std::move(promise);
|
||||||
}
|
}
|
||||||
|
file_manager_->download(file_id, download_file_callback_, priority, offset, limit, std::move(download_promise));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Td::on_file_download_finished(FileId file_id) {
|
void Td::on_file_download_finished(FileId file_id) {
|
||||||
@ -6468,8 +6471,8 @@ void Td::on_request(uint64 id, const td_api::getFileDownloadedPrefixSize &reques
|
|||||||
|
|
||||||
void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) {
|
void Td::on_request(uint64 id, const td_api::cancelDownloadFile &request) {
|
||||||
file_manager_->download(FileId(request.file_id_, 0), nullptr, request.only_if_pending_ ? -1 : 0,
|
file_manager_->download(FileId(request.file_id_, 0), nullptr, request.only_if_pending_ ? -1 : 0,
|
||||||
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::KEEP_DOWNLOAD_LIMIT);
|
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::KEEP_DOWNLOAD_LIMIT,
|
||||||
|
Promise<td_api::object_ptr<td_api::file>>());
|
||||||
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
|
send_closure(actor_id(this), &Td::send_result, id, make_tl_object<td_api::ok>());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,11 +83,12 @@ class FileDownloadGenerateActor final : public FileGenerateActor {
|
|||||||
};
|
};
|
||||||
|
|
||||||
send_closure(G()->file_manager(), &FileManager::download, file_id_, std::make_shared<Callback>(actor_id(this)), 1,
|
send_closure(G()->file_manager(), &FileManager::download, file_id_, std::make_shared<Callback>(actor_id(this)), 1,
|
||||||
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::KEEP_DOWNLOAD_LIMIT);
|
FileManager::KEEP_DOWNLOAD_OFFSET, FileManager::KEEP_DOWNLOAD_LIMIT,
|
||||||
|
Promise<td_api::object_ptr<td_api::file>>());
|
||||||
}
|
}
|
||||||
void hangup() final {
|
void hangup() final {
|
||||||
send_closure(G()->file_manager(), &FileManager::download, file_id_, nullptr, 0, FileManager::KEEP_DOWNLOAD_OFFSET,
|
send_closure(G()->file_manager(), &FileManager::download, file_id_, nullptr, 0, FileManager::KEEP_DOWNLOAD_OFFSET,
|
||||||
FileManager::KEEP_DOWNLOAD_LIMIT);
|
FileManager::KEEP_DOWNLOAD_LIMIT, Promise<td_api::object_ptr<td_api::file>>());
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2220,15 +2220,16 @@ void FileManager::delete_file(FileId file_id, Promise<Unit> promise, const char
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority, int64 offset,
|
void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority, int64 offset,
|
||||||
int64 limit) {
|
int64 limit, Promise<td_api::object_ptr<td_api::file>> promise) {
|
||||||
LOG(INFO) << "Download file " << file_id << " with priority " << new_priority;
|
LOG(INFO) << "Download file " << file_id << " with priority " << new_priority;
|
||||||
auto node = get_sync_file_node(file_id);
|
auto node = get_sync_file_node(file_id);
|
||||||
if (!node) {
|
if (!node) {
|
||||||
LOG(INFO) << "File " << file_id << " not found";
|
LOG(INFO) << "File " << file_id << " not found";
|
||||||
|
auto error = Status::Error(400, "File not found");
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback->on_download_error(file_id, Status::Error(400, "File not found"));
|
callback->on_download_error(file_id, error.clone());
|
||||||
}
|
}
|
||||||
return;
|
return promise.set_error(std::move(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto status = check_local_location(node, true);
|
auto status = check_local_location(node, true);
|
||||||
@ -2240,22 +2241,23 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
|
|||||||
if (callback) {
|
if (callback) {
|
||||||
callback->on_download_ok(file_id);
|
callback->on_download_ok(file_id);
|
||||||
}
|
}
|
||||||
return;
|
return promise.set_value(get_file_object(file_id, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
FileView file_view(node);
|
FileView file_view(node);
|
||||||
if (!file_view.can_download_from_server() && !file_view.can_generate()) {
|
if (!file_view.can_download_from_server() && !file_view.can_generate()) {
|
||||||
LOG(INFO) << "File " << file_id << " can't be downloaded";
|
LOG(INFO) << "File " << file_id << " can't be downloaded";
|
||||||
|
auto error = Status::Error(400, "Can't download or generate the file");
|
||||||
if (callback) {
|
if (callback) {
|
||||||
callback->on_download_error(file_id, Status::Error(400, "Can't download or generate file"));
|
callback->on_download_error(file_id, error.clone());
|
||||||
}
|
}
|
||||||
return;
|
return promise.set_error(std::move(error));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (new_priority == -1) {
|
if (new_priority == -1) {
|
||||||
if (node->is_download_started_) {
|
if (node->is_download_started_) {
|
||||||
LOG(INFO) << "File " << file_id << " is being downloaded";
|
LOG(INFO) << "File " << file_id << " is being downloaded";
|
||||||
return;
|
return promise.set_value(get_file_object(file_id, false));
|
||||||
}
|
}
|
||||||
new_priority = 0;
|
new_priority = 0;
|
||||||
}
|
}
|
||||||
@ -2285,6 +2287,7 @@ void FileManager::download(FileId file_id, std::shared_ptr<DownloadCallback> cal
|
|||||||
run_download(node, true);
|
run_download(node, true);
|
||||||
|
|
||||||
try_flush_node(node, "download");
|
try_flush_node(node, "download");
|
||||||
|
promise.set_value(get_file_object(file_id, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
void FileManager::run_download(FileNodePtr node, bool force_update_priority) {
|
void FileManager::run_download(FileNodePtr node, bool force_update_priority) {
|
||||||
|
@ -453,7 +453,7 @@ class FileManager final : public FileLoadManager::Callback {
|
|||||||
void check_local_location(FileId file_id, bool skip_file_size_checks);
|
void check_local_location(FileId file_id, bool skip_file_size_checks);
|
||||||
|
|
||||||
void download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority, int64 offset,
|
void download(FileId file_id, std::shared_ptr<DownloadCallback> callback, int32 new_priority, int64 offset,
|
||||||
int64 limit);
|
int64 limit, Promise<td_api::object_ptr<td_api::file>> promise);
|
||||||
void upload(FileId file_id, std::shared_ptr<UploadCallback> callback, int32 new_priority, uint64 upload_order);
|
void upload(FileId file_id, std::shared_ptr<UploadCallback> callback, int32 new_priority, uint64 upload_order);
|
||||||
void resume_upload(FileId file_id, std::vector<int> bad_parts, std::shared_ptr<UploadCallback> callback,
|
void resume_upload(FileId file_id, std::vector<int> bad_parts, std::shared_ptr<UploadCallback> callback,
|
||||||
int32 new_priority, uint64 upload_order, bool force = false, bool prefer_small = false);
|
int32 new_priority, uint64 upload_order, bool force = false, bool prefer_small = false);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user