61 lines
2.0 KiB
C++
61 lines
2.0 KiB
C++
|
#include "common.h"
|
||
|
#include "../../config.h"
|
||
|
#include "../../servehelper.h"
|
||
|
#include "../../pixivclient.h"
|
||
|
|
||
|
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) {
|
||
|
auto proxy_url = [&](std::string url) {
|
||
|
return config.image_proxy_url + remove_origin(std::move(url));
|
||
|
};
|
||
|
|
||
|
Element header("header");
|
||
|
if (user.cover_images) {
|
||
|
header.nodes.push_back(Element("a", {{"href", proxy_url(original_or_thumbnail(*user.cover_images))}}, {
|
||
|
Element("img", {{"class", "cover"}, {"src", proxy_url(thumbnail_or_original(*user.cover_images))}}, {})
|
||
|
}));
|
||
|
}
|
||
|
|
||
|
header.nodes.push_back(Element("div", {{"class", "usermetadata"}}, {
|
||
|
Element("a", {{"href", proxy_url(original_or_thumbnail(user.profile_pictures))}}, {
|
||
|
Element("img", {{"class", "profilepicture"}, {"src", proxy_url(thumbnail_or_original(user.profile_pictures))}}, {})
|
||
|
}),
|
||
|
Element("div", {
|
||
|
Element("p", {Element("b", {user.display_name}), " (@", user.username, ")"}),
|
||
|
generate_user_links(user)
|
||
|
})
|
||
|
}));
|
||
|
return header;
|
||
|
}
|
||
|
|
||
|
static inline Element generate_user_links(const User& user) {
|
||
|
Element p("p");
|
||
|
for (const auto &[name, url] : user.links) {
|
||
|
if (!p.nodes.empty()) {
|
||
|
p.nodes.push_back(", ");
|
||
|
}
|
||
|
p.nodes.push_back(Element("a", {{"href", url}}, {name}));
|
||
|
}
|
||
|
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 "";
|
||
|
}
|