From 1064fb2d6a85f2fe048135a6292bb0941979ed2f Mon Sep 17 00:00:00 2001 From: levlam Date: Tue, 14 Feb 2023 16:15:13 +0300 Subject: [PATCH] Move inputSticker checks to StickersManager::prepare_input_file. --- td/telegram/StickersManager.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/td/telegram/StickersManager.cpp b/td/telegram/StickersManager.cpp index 7b4373a88..7da6c205f 100644 --- a/td/telegram/StickersManager.cpp +++ b/td/telegram/StickersManager.cpp @@ -8006,6 +8006,10 @@ Result> StickersManager::prepare_input_sticker(td Result> StickersManager::prepare_input_file( const tl_object_ptr &input_file, StickerFormat sticker_format, StickerType sticker_type, bool for_thumbnail) { + if (sticker_format == StickerFormat::Unknown) { + return Status::Error(400, "Sticker format must be non-empty"); + } + auto file_type = sticker_format == StickerFormat::Tgs ? FileType::Sticker : FileType::Document; TRY_RESULT(file_id, td_->file_manager_->get_input_file_id(file_type, input_file, DialogId(), for_thumbnail, false)); if (file_id.empty()) { @@ -8045,6 +8049,14 @@ Result> StickersManager::prepare_input_file( is_local = true; } } + if (is_url) { + if (sticker_format == StickerFormat::Tgs) { + return Status::Error(400, "Animated stickers can't be uploaded by URL"); + } + if (sticker_format == StickerFormat::Webm) { + return Status::Error(400, "Video stickers can't be uploaded by URL"); + } + } return std::make_tuple(file_id, is_url, is_local); } @@ -8062,11 +8074,6 @@ FileId StickersManager::upload_sticker_file(UserId user_id, StickerFormat sticke return FileId(); } - if (sticker_format == StickerFormat::Unknown) { - promise.set_error(Status::Error(400, "Sticker format must be non-empty")); - return FileId(); - } - // StickerType::Regular has less restrictions auto r_file_id = prepare_input_file(input_file, sticker_format, StickerType::Regular, false); if (r_file_id.is_error()) { @@ -8189,10 +8196,6 @@ void StickersManager::create_new_sticker_set(UserId user_id, string title, strin return promise.set_error(Status::Error(400, "Only custom emoji stickers support repainting")); } - if (sticker_format == StickerFormat::Unknown) { - return promise.set_error(Status::Error(400, "Sticker format must be non-empty")); - } - vector file_ids; file_ids.reserve(stickers.size()); vector local_file_ids; @@ -8205,9 +8208,6 @@ void StickersManager::create_new_sticker_set(UserId user_id, string title, strin auto file_id = std::get<0>(r_file_id.ok()); auto is_url = std::get<1>(r_file_id.ok()); auto is_local = std::get<2>(r_file_id.ok()); - if (is_sticker_format_animated(sticker_format) && is_url) { - return promise.set_error(Status::Error(400, "Animated stickers can't be uploaded by URL")); - } file_ids.push_back(file_id); if (is_url) {