td_api::cleanFileName.

GitOrigin-RevId: e03cf634eb6a1e8f7191ea2e6a62f8b8990b21d0
This commit is contained in:
levlam 2018-04-30 15:50:54 +03:00
parent 4913915a8e
commit 0fb07d3376
5 changed files with 19 additions and 0 deletions

View File

@ -2516,6 +2516,9 @@ getFileMimeType file_name:string = Text;
//@description Returns the extension of a file, guessed by its MIME type. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously @mime_type The MIME type of the file
getFileExtension mime_type:string = Text;
//@description Removes potentially dangerous characters from a file name. File name encoding supposed to be UTF-8. Returns an empty string on failure. This is an offline method. Can be called before authorization. Can be called synchronously @file_name The name of the file or path to the file
cleanFileName file_name:string = Text;
//@description Sends an inline query to a bot and returns its results. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires @bot_user_id The identifier of the target bot
//@chat_id Identifier of the chat, where the query was sent @user_location Location of the user, only if needed @query Text of the query @offset Offset of the first entry to return

Binary file not shown.

View File

@ -71,6 +71,7 @@
#include "td/mtproto/utils.h" // for create_storer, fetch_result, etc, TODO
#include "td/utils/buffer.h"
#include "td/utils/filesystem.h"
#include "td/utils/format.h"
#include "td/utils/MimeType.h"
#include "td/utils/misc.h"
@ -7129,6 +7130,11 @@ void Td::on_request(uint64 id, const td_api::getFileExtension &request) {
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
}
void Td::on_request(uint64 id, const td_api::cleanFileName &request) {
// don't check authorization state
send_closure(actor_id(this), &Td::send_result, id, do_static_request(request));
}
template <class T>
td_api::object_ptr<td_api::Object> Td::do_static_request(const T &request) {
return make_error(400, "Function can't be executed synchronously");
@ -7179,6 +7185,11 @@ td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::getFileEx
return make_tl_object<td_api::text>(MimeType::to_extension(request.mime_type_));
}
td_api::object_ptr<td_api::Object> Td::do_static_request(const td_api::cleanFileName &request) {
// don't check file name UTF-8 correctness
return make_tl_object<td_api::text>(clean_filename(request.file_name_));
}
// test
void Td::on_request(uint64 id, td_api::testNetwork &request) {
create_handler<TestQuery>(id)->send();

View File

@ -811,6 +811,8 @@ class Td final : public NetQueryCallback {
void on_request(uint64 id, const td_api::getFileExtension &request);
void on_request(uint64 id, const td_api::cleanFileName &request);
// test
void on_request(uint64 id, td_api::testNetwork &request);
void on_request(uint64 id, td_api::testGetDifference &request);
@ -831,6 +833,7 @@ class Td final : public NetQueryCallback {
static td_api::object_ptr<td_api::Object> do_static_request(td_api::parseTextEntities &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileMimeType &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::getFileExtension &request);
static td_api::object_ptr<td_api::Object> do_static_request(const td_api::cleanFileName &request);
Status init(DbKey key) TD_WARN_UNUSED_RESULT;
void clear();

View File

@ -2168,6 +2168,8 @@ class CliClient final : public Actor {
send_request(make_tl_object<td_api::getFileMimeType>(trim(args)));
} else if (op == "gfe") {
send_request(make_tl_object<td_api::getFileExtension>(trim(args)));
} else if (op == "cfn") {
send_request(make_tl_object<td_api::cleanFileName>(args));
} else {
op_not_found_count++;
}