Guard against missing user_webpage and social
This commit is contained in:
parent
00df5327f0
commit
1a9c9d1a53
|
@ -53,15 +53,14 @@ void from_json(const nlohmann::json& j, User& user) {
|
|||
user.profile_pictures.thumbnails.push_back(profile_img.at("main").get<std::string>());
|
||||
user.profile_pictures.original = get_original_profile_picture(user.profile_pictures.thumbnails.back());
|
||||
|
||||
if (j.contains("user_webpage")) {
|
||||
std::string user_webpage = j.at("user_webpage").get<std::string>();
|
||||
if (!user_webpage.empty()) {
|
||||
user.links.push_back({"Webpage", std::move(user_webpage)});
|
||||
}
|
||||
auto add_social_as_needed = [&](const char* key, const char* public_name) {
|
||||
nlohmann::json social = j.at("social");
|
||||
if (!social.is_object()) {
|
||||
return;
|
||||
}
|
||||
auto add_social_as_needed = [&](const char* key, const char* public_name) {
|
||||
nlohmann::json social = j["social"];
|
||||
if (!social.contains(key)) {
|
||||
return;
|
||||
}
|
||||
|
@ -69,12 +68,14 @@ void from_json(const nlohmann::json& j, User& user) {
|
|||
std::string url = social[key].at("url").get<std::string>();
|
||||
user.links.push_back({public_name, std::move(url)});
|
||||
};
|
||||
if (j.contains("social") && j["social"].is_object()) {
|
||||
add_social_as_needed("twitter", "Twitter");
|
||||
add_social_as_needed("instagram", "Instagram");
|
||||
add_social_as_needed("tumblr", "Tumblr");
|
||||
add_social_as_needed("facebook", "Facebook");
|
||||
add_social_as_needed("circlems", "Circle.ms");
|
||||
add_social_as_needed("pawoo", "Pawoo");
|
||||
}
|
||||
}
|
||||
|
||||
static std::regex resolution_path_regex("/c/(\\d+x\\d+)(.+)");
|
||||
|
|
Loading…
Reference in New Issue