Support audio thumbnail download.
This commit is contained in:
parent
3a275827e9
commit
90df870adb
@ -148,9 +148,25 @@ class WebFileDownloadGenerateActor final : public FileGenerateActor {
|
|||||||
};
|
};
|
||||||
ActorOwn<NetQueryCallback> net_callback_;
|
ActorOwn<NetQueryCallback> net_callback_;
|
||||||
|
|
||||||
Result<tl_object_ptr<telegram_api::inputWebFileGeoPointLocation>> parse_conversion() {
|
Result<tl_object_ptr<telegram_api::InputWebFileLocation>> parse_conversion() {
|
||||||
auto parts = full_split(Slice(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<telegram_api::inputWebFileAudioAlbumThumbLocation>(flags, nullptr, parts[2].str(), parts[3].str());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parts.size() != 9 || parts[1] != "map") {
|
||||||
return Status::Error("Wrong conversion");
|
return Status::Error("Wrong conversion");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -932,7 +932,7 @@ bool FileManager::are_modification_times_equal(int64 old_mtime, int64 new_mtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FileManager::is_remotely_generated_file(Slice conversion) {
|
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) {
|
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);
|
<< " bytes is too big" << reason);
|
||||||
};
|
};
|
||||||
if ((location.file_type_ == FileType::Thumbnail || location.file_type_ == FileType::EncryptedThumbnail) &&
|
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");
|
return get_file_size_error(" for a thumbnail");
|
||||||
}
|
}
|
||||||
if (size > MAX_FILE_SIZE) {
|
if (size > MAX_FILE_SIZE) {
|
||||||
@ -3250,6 +3251,35 @@ Result<FileId> FileManager::get_map_thumbnail_file_id(Location location, int32 z
|
|||||||
FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0);
|
FileLocationSource::FromUser, string(), std::move(conversion), owner_dialog_id, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Result<FileId> 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<td_api::InputFile> &file) {
|
FileType FileManager::guess_file_type(const tl_object_ptr<td_api::InputFile> &file) {
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
return FileType::Temp;
|
return FileType::Temp;
|
||||||
|
@ -489,6 +489,9 @@ class FileManager final : public FileLoadManager::Callback {
|
|||||||
Result<FileId> get_map_thumbnail_file_id(Location location, int32 zoom, int32 width, int32 height, int32 scale,
|
Result<FileId> get_map_thumbnail_file_id(Location location, int32 zoom, int32 width, int32 height, int32 scale,
|
||||||
DialogId owner_dialog_id) TD_WARN_UNUSED_RESULT;
|
DialogId owner_dialog_id) TD_WARN_UNUSED_RESULT;
|
||||||
|
|
||||||
|
Result<FileId> 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<td_api::InputFile> &file);
|
FileType guess_file_type(const tl_object_ptr<td_api::InputFile> &file);
|
||||||
|
|
||||||
vector<tl_object_ptr<telegram_api::InputDocument>> get_input_documents(const vector<FileId> &file_ids);
|
vector<tl_object_ptr<telegram_api::InputDocument>> get_input_documents(const vector<FileId> &file_ids);
|
||||||
|
Loading…
Reference in New Issue
Block a user