Fix suggested name for generate, local and URL files.

GitOrigin-RevId: 2f203b2964f4b7da08346a7147e51af027baa2d2
This commit is contained in:
levlam 2018-02-20 01:28:06 +03:00
parent d3c980e5d3
commit d475864012
5 changed files with 52 additions and 13 deletions

View File

@ -15334,15 +15334,9 @@ Result<MessagesManager::InputMessageContent> MessagesManager::process_input_mess
file_id = r_file_id.ok();
CHECK(file_id.is_valid());
file_view = td_->file_manager_->get_file_view(file_id);
if (file_view.has_local_location()) {
const PathView path_view(file_view.local_location().path_);
file_name = path_view.file_name().str();
mime_type = MimeType::from_extension(path_view.extension());
} else if (file_view.has_generate_location()) {
const PathView path_view(file_view.generate_location().original_path_);
file_name = path_view.file_name().str();
mime_type = MimeType::from_extension(path_view.extension());
}
const PathView path_view(file_view.suggested_name());
file_name = path_view.file_name().str();
mime_type = MimeType::from_extension(path_view.extension());
}
FileId thumbnail_file_id;

View File

@ -903,6 +903,18 @@ class LocalFileLocation {
return variant_.get<2>();
}
CSlice file_name() const {
switch (type()) {
case Type::Partial:
return partial().path_;
case Type::Full:
return full().path_;
case Type::Empty:
default:
return CSlice();
}
}
template <class StorerT>
void store(StorerT &storer) const {
using td::store;

View File

@ -35,21 +35,26 @@
namespace td {
static int VERBOSITY_NAME(update_file) = VERBOSITY_NAME(INFO);
FileNode *FileNodePtr::operator->() const {
return get();
}
FileNode &FileNodePtr::operator*() const {
return *get();
}
FileNode *FileNodePtr::get() const {
auto res = get_unsafe();
CHECK(res);
return res;
}
FileNode *FileNodePtr::get_unsafe() const {
CHECK(file_manager_ != nullptr);
return file_manager_->get_file_node_raw(file_id_);
}
FileNodePtr::operator bool() const {
return file_manager_ != nullptr && get_unsafe() != nullptr;
}
@ -227,6 +232,26 @@ void FileNode::on_info_flushed() {
info_changed_flag_ = false;
}
CSlice FileNode::suggested_name() const {
if (!remote_name_.empty()) {
return remote_name_;
}
CSlice local_name(local_.file_name());
if (!local_name.empty()) {
return local_name;
}
if (!url_.empty()) {
return url_;
}
if (generate_ != nullptr) {
CSlice generate_name(generate_->original_path_);
if (!generate_name.empty()) {
return generate_name;
}
}
return CSlice();
}
/*** FileView ***/
bool FileView::has_local_location() const {
return node_->local_.type() == LocalFileLocation::Type::Full;
@ -335,6 +360,10 @@ const string &FileView::remote_name() const {
return node_->remote_name_;
}
CSlice FileView::suggested_name() const {
return node_->suggested_name();
}
DialogId FileView::owner_dialog_id() const {
return node_->owner_dialog_id_;
}
@ -1273,7 +1302,7 @@ bool FileManager::set_content(FileId file_id, BufferSlice bytes) {
node->download_id_ = id;
node->is_download_started_ = true;
send_closure(file_load_manager_, &FileLoadManager::from_bytes, id, node->remote_.full().file_type_, std::move(bytes),
node->remote_name_);
node->suggested_name().str());
return true;
}
@ -1423,7 +1452,7 @@ void FileManager::run_download(FileNodePtr node) {
node->download_id_ = id;
node->is_download_started_ = false;
send_closure(file_load_manager_, &FileLoadManager::download, id, node->remote_.full(), node->local_, node->size_,
node->remote_name_, node->encryption_key_, priority);
node->suggested_name().str(), node->encryption_key_, priority);
}
void FileManager::resume_upload(FileId file_id, std::vector<int> bad_parts, std::shared_ptr<UploadCallback> callback,
@ -1566,7 +1595,7 @@ void FileManager::run_generate(FileNodePtr node) {
QueryId id = queries_container_.create(Query{file_id, Query::Generate});
node->generate_id_ = id;
send_closure(file_generate_manager_, &FileGenerateManager::generate_file, id, *node->generate_, node->local_,
node->remote_name_, [file_manager = this, id] {
node->suggested_name().str(), [file_manager = this, id] {
class Callback : public FileGenerateCallback {
ActorId<FileManager> actor_;
uint64 query_id_;

View File

@ -73,6 +73,8 @@ class FileNode {
void on_pmc_flushed();
void on_info_flushed();
CSlice suggested_name() const;
private:
friend class FileView;
friend class FileManager;
@ -181,6 +183,8 @@ class FileView {
const string &remote_name() const;
CSlice suggested_name() const;
DialogId owner_dialog_id() const;
bool get_by_hash() const;

View File

@ -28,7 +28,7 @@ void FileManager::store_file(FileId file_id, StorerT &storer, int32 ttl) const {
file_store_type = FileStoreType::Remote;
} else if (file_view.has_local_location()) {
file_store_type = FileStoreType::Local;
} else if (!file_view.url().empty()) {
} else if (file_view.has_url()) {
file_store_type = FileStoreType::Url;
} else if (file_view.has_generate_location()) {
file_store_type = FileStoreType::Generate;