diff --git a/td/telegram/files/FileGenerateManager.cpp b/td/telegram/files/FileGenerateManager.cpp index 6b37f8334..5a1e29d5e 100644 --- a/td/telegram/files/FileGenerateManager.cpp +++ b/td/telegram/files/FileGenerateManager.cpp @@ -148,9 +148,25 @@ class WebFileDownloadGenerateActor final : public FileGenerateActor { }; ActorOwn net_callback_; - Result> parse_conversion() { + Result> parse_conversion() { auto parts = full_split(Slice(conversion_), '#'); - if (parts.size() != 9 || !parts[0].empty() || parts[1] != "map" || !parts[8].empty()) { + if (parts.size() <= 2 || !parts[0].empty() || !parts.back().empty()) { + return Status::Error("Wrong conversion"); + } + + if (parts.size() == 5 && parts[1] == "audio_t") { + // music thumbnail + if (parts[2].empty() && parts[3].empty()) { + return Status::Error("Title or performer must be non-empty"); + } + + file_name_ = PSTRING() << "music_thumbnail_" << parts[3] << " - " << parts[2] << ".jpg"; + + auto flags = telegram_api::inputWebFileAudioAlbumThumbLocation::TITLE_MASK; + return make_tl_object(flags, nullptr, parts[2].str(), parts[3].str()); + } + + if (parts.size() != 9 || parts[1] != "map") { return Status::Error("Wrong conversion"); } diff --git a/td/telegram/files/FileManager.cpp b/td/telegram/files/FileManager.cpp index a4ba39d22..bac403435 100644 --- a/td/telegram/files/FileManager.cpp +++ b/td/telegram/files/FileManager.cpp @@ -932,7 +932,7 @@ bool FileManager::are_modification_times_equal(int64 old_mtime, int64 new_mtime) } bool FileManager::is_remotely_generated_file(Slice conversion) { - return begins_with(conversion, "#map#"); + return begins_with(conversion, "#map#") || begins_with(conversion, "#audio_t#"); } Status FileManager::check_local_location(FullLocalFileLocation &location, int64 &size, bool skip_file_size_checks) { @@ -987,7 +987,8 @@ Status FileManager::check_local_location(FullLocalFileLocation &location, int64 << " bytes is too big" << reason); }; if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) && - size > MAX_THUMBNAIL_SIZE && !begins_with(PathView(location.path_).file_name(), "map")) { + size > MAX_THUMBNAIL_SIZE && !begins_with(PathView(location.path_).file_name(), "map") && + !begins_with(PathView(location.path_).file_name(), "music_thumbnail")) { return get_file_size_error(" for a thumbnail"); } if (size > MAX_FILE_SIZE) { @@ -3250,6 +3251,35 @@ Result FileManager::get_map_thumbnail_file_id(Location location, int32 z FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0); } +Result FileManager::get_audio_thumbnail_file_id(string title, string performer, DialogId owner_dialog_id) { + if (!clean_input_string(title)) { + return Status::Error(400, "Title must be encoded in UTF-8"); + } + if (!clean_input_string(performer)) { + return Status::Error(400, "Performer must be encoded in UTF-8"); + } + for (auto &c : title) { + if (c == '\n' || c == '#') { + c = ' '; + } + } + for (auto &c : performer) { + if (c == '\n' || c == '#') { + c = ' '; + } + } + title = trim(title); + performer = trim(performer); + if (title.empty() && performer.empty()) { + return Status::Error(400, "Title or performer must be non-empty"); + } + + string conversion = PSTRING() << "#audio_t#" << title << '#' << performer << '#'; + return register_generate( + owner_dialog_id.get_type() == DialogType::SecretChat ? FileType::EncryptedThumbnail : FileType::Thumbnail, + FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0); +} + FileType FileManager::guess_file_type(const tl_object_ptr &file) { if (file == nullptr) { return FileType::Temp; diff --git a/td/telegram/files/FileManager.h b/td/telegram/files/FileManager.h index 0190539f9..13ad50dc3 100644 --- a/td/telegram/files/FileManager.h +++ b/td/telegram/files/FileManager.h @@ -489,6 +489,9 @@ class FileManager final : public FileLoadManager::Callback { Result get_map_thumbnail_file_id(Location location, int32 zoom, int32 width, int32 height, int32 scale, DialogId owner_dialog_id) TD_WARN_UNUSED_RESULT; + Result get_audio_thumbnail_file_id(string title, string performer, + DialogId owner_dialog_id) TD_WARN_UNUSED_RESULT; + FileType guess_file_type(const tl_object_ptr &file); vector> get_input_documents(const vector &file_ids);