Compare commits

..

No commits in common. "9259f7c198d335739c680d761da9a474cb6aa20b" and "421bbcd6a0a5b995a407380d122bb7136e4a2a0a" have entirely different histories.

2 changed files with 8 additions and 18 deletions

View File

@ -92,9 +92,7 @@ void from_json(const nlohmann::json& j, Illust& illust) {
bool full_data = j.contains("illust_details"); bool full_data = j.contains("illust_details");
const nlohmann::json& author_details = j.at("author_details"); const nlohmann::json& author_details = j.at("author_details");
const nlohmann::json& illust_details = full_data ? j.at("illust_details") : j; const nlohmann::json& illust_details = full_data ? j.at("illust_details") : j;
std::optional<nlohmann::json> images_metadata = illust_details.contains("illust_images") const nlohmann::json& images_metadata = illust_details.at("illust_images");
? std::optional(illust_details["illust_images"])
: std::nullopt;
author_details.at("user_account").get_to(illust.username); author_details.at("user_account").get_to(illust.username);
author_details.at("user_name").get_to(illust.user_display_name); author_details.at("user_name").get_to(illust.user_display_name);
@ -120,10 +118,10 @@ void from_json(const nlohmann::json& j, Illust& illust) {
illust.images.reserve(manga_a.size()); illust.images.reserve(manga_a.size());
for (size_t i = 0; i < manga_a.size(); i++) { for (size_t i = 0; i < manga_a.size(); i++) {
illust.images.push_back(get_illust_images(manga_a[i], images_metadata ? std::optional(images_metadata->at(i)) : std::nullopt)); illust.images.push_back(get_illust_images(manga_a[i], images_metadata.at(i)));
} }
} else { } else {
illust.images = {get_illust_images(illust_details, images_metadata ? std::optional(images_metadata->at(0)) : std::nullopt)}; illust.images = {get_illust_images(illust_details, images_metadata.at(0))};
} }
illust.page_count = to_ull(illust_details.at("page_count").get_ref<const nlohmann::json::string_t&>()); illust.page_count = to_ull(illust_details.at("page_count").get_ref<const nlohmann::json::string_t&>());
} }

View File

@ -125,25 +125,17 @@ static inline std::vector<blankie::html::Node> parse_description_line(const http
std::smatch sm; std::smatch sm;
while (std::regex_search(str, sm, blankie::murl::full_url_regex)) { while (std::regex_search(str, sm, blankie::murl::full_url_regex)) {
std::string prefix = sm.prefix(); if (sm.prefix().length()) {
std::string url_str = sm.str(0); nodes.push_back(sm.prefix());
std::string suffix = sm.suffix();
if (prefix.ends_with('(') && url_str.ends_with(')')) {
url_str.pop_back();
suffix.insert(0, 1, ')');
}
if (!prefix.empty()) {
nodes.push_back(std::move(prefix));
} }
blankie::murl::Url url(std::move(url_str)); blankie::murl::Url url(sm.str(0));
url_str = url.is_host_equal("pixiv.net") || url.is_host_equal("www.pixiv.net") std::string url_str = url.is_host_equal("pixiv.net") || url.is_host_equal("www.pixiv.net")
? proxy_pixiv_url(req, config, std::move(url)) ? proxy_pixiv_url(req, config, std::move(url))
: url.to_string(); : url.to_string();
nodes.push_back(Element("a", {{"href", url_str}}, {url_str})); nodes.push_back(Element("a", {{"href", url_str}}, {url_str}));
str = std::move(suffix); str = sm.suffix();
} }
if (!str.empty()) { if (!str.empty()) {
nodes.push_back(std::move(str)); nodes.push_back(std::move(str));