Add PixivClient::get_illusts
This commit is contained in:
parent
2c7103b56b
commit
f6447d9ec5
12
main.cpp
12
main.cpp
|
@ -52,6 +52,18 @@ int main(int argc, char** argv) {
|
||||||
});
|
});
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#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) {
|
server.Get("/debug/exception/known", [](const httplib::Request& req, httplib::Response& res) {
|
||||||
throw std::runtime_error("awoo");
|
throw std::runtime_error("awoo");
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,6 +22,22 @@ User PixivClient::get_user(uint64_t user_id) {
|
||||||
return this->_handle_result(std::move(res)).at("user_details").get<User>();
|
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) {
|
nlohmann::json PixivClient::_handle_result(httplib::Result res) {
|
||||||
if (!res) {
|
if (!res) {
|
||||||
throw HTTPLibException(res.error());
|
throw HTTPLibException(res.error());
|
||||||
|
|
|
@ -27,6 +27,7 @@ public:
|
||||||
PixivClient();
|
PixivClient();
|
||||||
|
|
||||||
User get_user(uint64_t user_id);
|
User get_user(uint64_t user_id);
|
||||||
|
std::vector<uint64_t> get_illusts(uint64_t user_id);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nlohmann::json _handle_result(httplib::Result res);
|
nlohmann::json _handle_result(httplib::Result res);
|
||||||
|
|
Loading…
Reference in New Issue