From 8524f948839e1ff17c48e23d9588ec17b980bd23 Mon Sep 17 00:00:00 2001 From: Marco Aceti Date: Thu, 12 Nov 2020 23:15:49 +0100 Subject: [PATCH] Add --no-file-limit option Co-Authored-By: giuseppeM99 --- telegram-bot-api/Client.cpp | 4 ++-- telegram-bot-api/ClientParameters.h | 1 + telegram-bot-api/telegram-bot-api.cpp | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index c1d7a0b..9f425dd 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -3805,7 +3805,7 @@ void Client::on_update_file(object_ptr file) { if (!is_file_being_downloaded(file_id)) { return; } - if (!parameters_->local_mode_ && file->local_->downloaded_size_ > MAX_DOWNLOAD_FILE_SIZE) { + if ((!parameters_->local_mode_ || !parameters_->no_file_limit) && file->local_->downloaded_size_ > MAX_DOWNLOAD_FILE_SIZE) { if (file->local_->is_downloading_active_) { send_request(make_object(file_id, false), std::make_unique()); @@ -7503,7 +7503,7 @@ td::Status Client::process_toggle_group_invites_query(PromisedQueryPtr &query) { //end custom methods impl void Client::do_get_file(object_ptr file, PromisedQueryPtr query) { - if (!parameters_->local_mode_ && + if ((!parameters_->local_mode_ || !parameters_->no_file_limit_) && td::max(file->expected_size_, file->local_->downloaded_size_) > MAX_DOWNLOAD_FILE_SIZE) { // speculative check return fail_query(400, "Bad Request: file is too big", std::move(query)); } diff --git a/telegram-bot-api/ClientParameters.h b/telegram-bot-api/ClientParameters.h index 276b741..b7c9e68 100644 --- a/telegram-bot-api/ClientParameters.h +++ b/telegram-bot-api/ClientParameters.h @@ -57,6 +57,7 @@ struct ClientParameters { bool local_mode_ = false; bool allow_http_ = false; bool use_relative_path_ = false; + bool no_file_limit = true; td::int32 api_id_ = 0; td::string api_hash_; diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 1405987..04d070b 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -169,8 +169,10 @@ int main(int argc, char *argv[]) { options.set_usage(td::Slice(argv[0]), "--api-id= --api-hash= [--local] [OPTION]..."); options.set_description("Telegram Bot API server"); options.add_option('h', "help", "display this help text and exit", [&] { need_print_usage = true; }); - options.add_option('\0', "local", "allow the Bot API server to serve local requests", + options.add_option('\0', "local", "allow the Bot API server to serve local requests and disables the file limits", [&] { parameters->local_mode_ = true; }); + options.add_option('\0', "no-file-limit", "disable the file limits", + [&] { parameters->no_file_limit_ = true; }); options.add_option('\0', "insecure", "allow the Bot API to send request via insecure HTTP", [&] { parameters->allow_http_ = true; }); options.add_option('\0', "relative", "use relative file path in local mode", [&] { parameters->use_relative_path_ = true; });