2023-04-04 17:01:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <utility>
|
|
|
|
#include <optional>
|
|
|
|
|
|
|
|
#include <httplib/httplib.h>
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
|
|
|
|
struct Images {
|
|
|
|
std::optional<std::string> original;
|
|
|
|
std::vector<std::string> thumbnails;
|
2023-04-07 16:58:38 +00:00
|
|
|
|
|
|
|
const std::string& original_or_thumbnail() const;
|
|
|
|
const std::string& thumbnail_or_original() const;
|
2023-04-04 17:01:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct User {
|
|
|
|
std::string username;
|
|
|
|
std::string display_name;
|
|
|
|
uint64_t user_id;
|
|
|
|
|
|
|
|
std::optional<Images> cover_images;
|
|
|
|
Images profile_pictures;
|
|
|
|
std::vector<std::pair<std::string, std::string>> links;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PixivClient {
|
|
|
|
public:
|
|
|
|
PixivClient();
|
|
|
|
|
|
|
|
User get_user(uint64_t user_id);
|
2023-04-07 12:00:16 +00:00
|
|
|
std::vector<uint64_t> get_illusts(uint64_t user_id);
|
2023-04-04 17:01:50 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
nlohmann::json _handle_result(httplib::Result res);
|
|
|
|
httplib::Client _www_pixiv_net_client{"https://www.pixiv.net"};
|
|
|
|
};
|
|
|
|
|
|
|
|
class HTTPLibException : public std::exception {
|
|
|
|
public:
|
|
|
|
HTTPLibException(httplib::Error error) {
|
|
|
|
this->_message = httplib::to_string(error);
|
|
|
|
}
|
|
|
|
|
|
|
|
const constexpr char* what() const noexcept {
|
|
|
|
return this->_message.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string _message;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PixivException : public std::exception {
|
|
|
|
public:
|
|
|
|
PixivException(int status_, std::string message) : status(status_), _message(std::move(message)) {}
|
|
|
|
|
|
|
|
const constexpr char* what() const noexcept {
|
|
|
|
return this->_message.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
int status;
|
|
|
|
|
|
|
|
private:
|
|
|
|
std::string _message;
|
|
|
|
};
|
|
|
|
|
|
|
|
void from_json(const nlohmann::json& j, User& user);
|