Add PixivClient::get_illusts

This commit is contained in:
blankie 2023-04-07 19:00:16 +07:00
parent 2c7103b56b
commit f6447d9ec5
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
3 changed files with 29 additions and 0 deletions

View File

@ -52,6 +52,18 @@ int main(int argc, char** argv) {
});
#ifndef NDEBUG
// TODO remove
server.Get("/debug/userillusts", [&](const httplib::Request& req, httplib::Response& res) {
std::vector<uint64_t> illusts = pixiv_client.get_illusts(2583663);
std::string output;
for (uint64_t i : illusts) {
output += std::to_string(i);
output += '\n';
}
res.set_content(std::move(output), "text/plain");
});
server.Get("/debug/exception/known", [](const httplib::Request& req, httplib::Response& res) {
throw std::runtime_error("awoo");
});

View File

@ -22,6 +22,22 @@ User PixivClient::get_user(uint64_t user_id) {
return this->_handle_result(std::move(res)).at("user_details").get<User>();
}
std::vector<uint64_t> PixivClient::get_illusts(uint64_t user_id) {
httplib::Result res = this->_www_pixiv_net_client.Get("/touch/ajax/illust/user_illusts", {
{"lang", "en"}, {"user_id", std::to_string(user_id)}
}, httplib::Headers());
nlohmann::json user_illust_ids = this->_handle_result(std::move(res)).at("user_illust_ids");
std::vector<uint64_t> ret;
ret.reserve(user_illust_ids.size());
for (auto &[_, i] : user_illust_ids.items()) {
ret.push_back(to_ull(std::move(i)));
}
return ret;
}
nlohmann::json PixivClient::_handle_result(httplib::Result res) {
if (!res) {
throw HTTPLibException(res.error());

View File

@ -27,6 +27,7 @@ public:
PixivClient();
User get_user(uint64_t user_id);
std::vector<uint64_t> get_illusts(uint64_t user_id);
private:
nlohmann::json _handle_result(httplib::Result res);