From 50afa93c577bed3eb9911d141d46f2e0d3ba2572 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Fri, 30 Apr 2021 21:04:47 +0200 Subject: Add 4chan file upload --- src/plugins/Fourchan.cpp | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'src/plugins/Fourchan.cpp') diff --git a/src/plugins/Fourchan.cpp b/src/plugins/Fourchan.cpp index 7cad54f..5e6a970 100644 --- a/src/plugins/Fourchan.cpp +++ b/src/plugins/Fourchan.cpp @@ -208,11 +208,8 @@ namespace QuickMedia { } } - // TODO: Merge with get_threads_internal - PluginResult FourchanThreadListPage::submit(const std::string &title, const std::string &url, std::vector &result_tabs) { - (void)title; - cached_media_urls.clear(); - + // TODO: Merge with lazy fetch + PluginResult FourchanThreadListPage::submit(const std::string&, const std::string &url, std::vector &result_tabs) { Json::Value json_root; DownloadResult result = download_json(json_root, fourchan_url + board_id + "/thread/" + url + ".json", {}, true); if(result != DownloadResult::OK) return download_result_to_plugin_result(result); @@ -299,8 +296,8 @@ namespace QuickMedia { comment_text.append(cp.text.data, cp.text.size); break; case CommentPiece::Type::QUOTE: - comment_text += '>'; - comment_text.append(cp.text.data, cp.text.size); + //comment_text += '>'; + //comment_text.append(cp.text.data, cp.text.size); //comment_text += '\n'; break; case CommentPiece::Type::QUOTELINK: { @@ -342,8 +339,7 @@ namespace QuickMedia { // thumbnails always has .jpg extension even if they are gifs or webm. std::string tim_str = std::to_string(tim.asInt64()); body_item->thumbnail_url = fourchan_image_url + board_id + "/" + tim_str + "s.jpg"; - body_item->attached_content_url = fourchan_image_url + board_id + "/" + tim_str + ext_str; - cached_media_urls.push_back(body_item->attached_content_url); + body_item->url = fourchan_image_url + board_id + "/" + tim_str + ext_str; sf::Vector2i thumbnail_size(64, 64); const Json::Value &tn_w = post["tn_w"]; @@ -358,7 +354,7 @@ namespace QuickMedia { auto body = create_body(); body->items = std::move(result_items); - result_tabs.push_back(Tab{std::move(body), std::make_unique(program, board_id, url, std::move(cached_media_urls)), nullptr}); + result_tabs.push_back(Tab{std::move(body), std::make_unique(program, board_id, url), nullptr}); return PluginResult::OK; } @@ -404,8 +400,8 @@ namespace QuickMedia { title_text.append(cp.text.data, cp.text.size); break; case CommentPiece::Type::QUOTE: - title_text += '>'; - title_text.append(cp.text.data, cp.text.size); + //title_text += '>'; + //title_text.append(cp.text.data, cp.text.size); //comment_text += '\n'; break; case CommentPiece::Type::QUOTELINK: { @@ -433,8 +429,8 @@ namespace QuickMedia { comment_text.append(cp.text.data, cp.text.size); break; case CommentPiece::Type::QUOTE: - comment_text += '>'; - comment_text.append(cp.text.data, cp.text.size); + //comment_text += '>'; + //comment_text.append(cp.text.data, cp.text.size); //comment_text += '\n'; break; case CommentPiece::Type::QUOTELINK: { @@ -535,7 +531,14 @@ namespace QuickMedia { } } - PostResult FourchanThreadPage::post_comment(const std::string &captcha_id, const std::string &comment) { + static std::string file_get_filename(const std::string &filepath) { + size_t index = filepath.rfind('/'); + if(index == std::string::npos) + return filepath.c_str(); + return filepath.c_str() + index + 1; + } + + PostResult FourchanThreadPage::post_comment(const std::string &captcha_id, const std::string &comment, const std::string &filepath) { std::string url = "https://sys.4chan.org/" + board_id + "/post"; std::vector additional_args = { @@ -546,6 +549,15 @@ namespace QuickMedia { CommandArg{"-F", "mode=regist"} }; + if(!filepath.empty()) { + std::string filename = file_get_filename(filepath); + if(filename[0] == '@') + filename = "\\" + filename; + + additional_args.push_back({ "-F", "upfile=@" + filepath }); + additional_args.push_back({ "-F", "filename=" + filename }); + } + if(pass_id.empty()) { additional_args.push_back(CommandArg{"-F", "g-recaptcha-response=" + captcha_id}); } else { @@ -569,6 +581,9 @@ namespace QuickMedia { return PostResult::BANNED; if(response.find("try again") != std::string::npos || response.find("No valid captcha") != std::string::npos) return PostResult::TRY_AGAIN; + if(response.find("Audio streams are not allowed") != std::string::npos) + return PostResult::FILE_TYPE_NOT_ALLOWED; + return PostResult::ERR; } -- cgit v1.2.3