diff --git a/main.cpp b/main.cpp index 36e01d3..66ff979 100644 --- a/main.cpp +++ b/main.cpp @@ -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 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"); }); diff --git a/pixivclient.cpp b/pixivclient.cpp index c2b2053..8eb5160 100644 --- a/pixivclient.cpp +++ b/pixivclient.cpp @@ -22,6 +22,22 @@ User PixivClient::get_user(uint64_t user_id) { return this->_handle_result(std::move(res)).at("user_details").get(); } +std::vector 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 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()); diff --git a/pixivclient.h b/pixivclient.h index 7505939..76eabb3 100644 --- a/pixivclient.h +++ b/pixivclient.h @@ -27,6 +27,7 @@ public: PixivClient(); User get_user(uint64_t user_id); + std::vector get_illusts(uint64_t user_id); private: nlohmann::json _handle_result(httplib::Result res);