Move original_or_thumbnail and thumbnail_or_original to Images
This commit is contained in:
parent
1f877e4d4e
commit
2750953d5c
|
@ -8,6 +8,26 @@ static inline std::optional<std::string> get_1920x960_cover_image(blankie::murl:
|
||||||
static inline std::optional<std::string> get_original_cover_image(blankie::murl::Url url);
|
static inline std::optional<std::string> get_original_cover_image(blankie::murl::Url url);
|
||||||
static inline std::optional<std::string> get_original_profile_picture(blankie::murl::Url url);
|
static inline std::optional<std::string> get_original_profile_picture(blankie::murl::Url url);
|
||||||
|
|
||||||
|
const std::string& Images::original_or_thumbnail() const {
|
||||||
|
if (this->original) {
|
||||||
|
return *this->original;
|
||||||
|
}
|
||||||
|
if (!this->thumbnails.empty()) {
|
||||||
|
return this->thumbnails.back();
|
||||||
|
}
|
||||||
|
throw std::runtime_error("Images does not contain any images");
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string& Images::thumbnail_or_original() const {
|
||||||
|
if (!this->thumbnails.empty()) {
|
||||||
|
return this->thumbnails.back();
|
||||||
|
}
|
||||||
|
if (this->original) {
|
||||||
|
return *this->original;
|
||||||
|
}
|
||||||
|
throw std::runtime_error("Images does not contain any images");
|
||||||
|
}
|
||||||
|
|
||||||
PixivClient::PixivClient() {
|
PixivClient::PixivClient() {
|
||||||
this->_www_pixiv_net_client.set_keep_alive(true);
|
this->_www_pixiv_net_client.set_keep_alive(true);
|
||||||
this->_www_pixiv_net_client.set_default_headers({
|
this->_www_pixiv_net_client.set_default_headers({
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
struct Images {
|
struct Images {
|
||||||
std::optional<std::string> original;
|
std::optional<std::string> original;
|
||||||
std::vector<std::string> thumbnails;
|
std::vector<std::string> thumbnails;
|
||||||
|
|
||||||
|
const std::string& original_or_thumbnail() const;
|
||||||
|
const std::string& thumbnail_or_original() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct User {
|
struct User {
|
||||||
|
|
|
@ -4,21 +4,19 @@
|
||||||
#include "../../pixivclient.h"
|
#include "../../pixivclient.h"
|
||||||
|
|
||||||
static inline Element generate_user_links(const User& user);
|
static inline Element generate_user_links(const User& user);
|
||||||
static std::string thumbnail_or_original(const Images& images);
|
|
||||||
static std::string original_or_thumbnail(const Images& images);
|
|
||||||
|
|
||||||
Element generate_user_header(const User& user, const Config& config) {
|
Element generate_user_header(const User& user, const Config& config) {
|
||||||
Element header("header");
|
Element header("header");
|
||||||
if (user.cover_images) {
|
if (user.cover_images) {
|
||||||
std::string cover_original = proxy_image_url(config, original_or_thumbnail(*user.cover_images));
|
std::string cover_original = proxy_image_url(config, user.cover_images->original_or_thumbnail());
|
||||||
std::string cover_thumbnail = proxy_image_url(config, thumbnail_or_original(*user.cover_images));
|
std::string cover_thumbnail = proxy_image_url(config, user.cover_images->thumbnail_or_original());
|
||||||
header.nodes.push_back(Element("a", {{"href", std::move(cover_original)}}, {
|
header.nodes.push_back(Element("a", {{"href", std::move(cover_original)}}, {
|
||||||
Element("img", {{"class", "cover"}, {"src", std::move(cover_thumbnail)}}, {})
|
Element("img", {{"class", "cover"}, {"src", std::move(cover_thumbnail)}}, {})
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string profile_picture_original = proxy_image_url(config, original_or_thumbnail(user.profile_pictures));
|
std::string profile_picture_original = proxy_image_url(config, user.profile_pictures.original_or_thumbnail());
|
||||||
std::string profile_picture_thumbnail = proxy_image_url(config, thumbnail_or_original(user.profile_pictures));
|
std::string profile_picture_thumbnail = proxy_image_url(config, user.profile_pictures.thumbnail_or_original());
|
||||||
header.nodes.push_back(Element("div", {{"class", "usermetadata"}}, {
|
header.nodes.push_back(Element("div", {{"class", "usermetadata"}}, {
|
||||||
Element("a", {{"href", std::move(profile_picture_original)}}, {
|
Element("a", {{"href", std::move(profile_picture_original)}}, {
|
||||||
Element("img", {{"class", "profilepicture"}, {"src", std::move(profile_picture_thumbnail)}}, {})
|
Element("img", {{"class", "profilepicture"}, {"src", std::move(profile_picture_thumbnail)}}, {})
|
||||||
|
@ -41,20 +39,3 @@ static inline Element generate_user_links(const User& user) {
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static std::string thumbnail_or_original(const Images& images) {
|
|
||||||
if (!images.thumbnails.empty()) {
|
|
||||||
return images.thumbnails.back();
|
|
||||||
}
|
|
||||||
return images.original.value_or("");
|
|
||||||
}
|
|
||||||
|
|
||||||
static std::string original_or_thumbnail(const Images& images) {
|
|
||||||
if (images.original) {
|
|
||||||
return *images.original;
|
|
||||||
}
|
|
||||||
if (!images.thumbnails.empty()) {
|
|
||||||
return images.thumbnails.back();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in New Issue