2023-04-07 15:06:31 +00:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "../routes.h"
|
2023-04-07 15:13:25 +00:00
|
|
|
#include "../../numberhelper.h"
|
2023-04-07 15:06:31 +00:00
|
|
|
#include "../../servehelper.h"
|
|
|
|
#include "../../pixivclient.h"
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
void user_illustrations_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) {
|
|
|
|
uint64_t user_id = to_ull(req.matches[1].str());
|
|
|
|
uint64_t page = req.has_param("p") ? to_ull(req.get_param_value("p")) - 1 : 0;
|
|
|
|
User user;
|
2023-04-08 16:27:45 +00:00
|
|
|
Illusts illusts;
|
2023-04-07 15:06:31 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
user = pixiv_client.get_user(user_id);
|
2023-04-08 16:27:45 +00:00
|
|
|
illusts = pixiv_client.get_illusts(user_id, page);
|
2023-04-07 15:06:31 +00:00
|
|
|
} catch (const PixivException& e) {
|
|
|
|
if (e.status == 404) {
|
|
|
|
res.status = 404;
|
|
|
|
serve_error(req, res, config, "404: User not found", e.what());
|
|
|
|
} else {
|
|
|
|
res.status = 500;
|
|
|
|
serve_error(req, res, config, "500: Internal server error", "Failed to fetch user information", e.what());
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} catch (const std::exception& e) {
|
|
|
|
res.status = 500;
|
|
|
|
serve_error(req, res, config, "500: Internal server error", "Failed to fetch user information", e.what());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element body("body", {
|
|
|
|
generate_user_header(std::move(user), config),
|
2023-04-28 09:00:21 +00:00
|
|
|
generate_illusts_pager(req, config, illusts, page, "illusts")
|
2023-04-07 15:06:31 +00:00
|
|
|
});
|
2023-04-09 13:50:44 +00:00
|
|
|
serve(req, res, config, user.display_name + "'s illustrations", std::move(body));
|
2023-04-07 15:06:31 +00:00
|
|
|
}
|