Redirect /users/\d+ to /users/\1/illustrations

This commit is contained in:
blankie 2023-04-09 22:33:14 +07:00
parent 4e4255618a
commit 933affe6b4
Signed by: blankie
GPG Key ID: CC15FC822C7F61F5
4 changed files with 2 additions and 30 deletions

View File

@ -25,7 +25,7 @@ add_link_options(${FLAGS})
add_executable(${PROJECT_NAME} main.cpp misc.cpp config.cpp servehelper.cpp numberhelper.cpp pixivclient.cpp pixivmodels.cpp add_executable(${PROJECT_NAME} main.cpp misc.cpp config.cpp servehelper.cpp numberhelper.cpp pixivclient.cpp pixivmodels.cpp
blankie/serializer.cpp blankie/escape.cpp blankie/murl.cpp blankie/serializer.cpp blankie/escape.cpp blankie/murl.cpp
routes/home.cpp routes/css.cpp routes/artworks.cpp routes/users/common.cpp routes/users/users.cpp routes/users/illustrations.cpp) routes/home.cpp routes/css.cpp routes/artworks.cpp routes/users/common.cpp routes/users/illustrations.cpp)
set_target_properties(${PROJECT_NAME} set_target_properties(${PROJECT_NAME}
PROPERTIES PROPERTIES
CXX_STANDARD 20 CXX_STANDARD 20

View File

@ -29,7 +29,7 @@ int main(int argc, char** argv) {
server.Get("/style\\.css", css_route); server.Get("/style\\.css", css_route);
server.Get("/users/(\\d+)", [&](const httplib::Request& req, httplib::Response& res) { server.Get("/users/(\\d+)", [&](const httplib::Request& req, httplib::Response& res) {
users_route(req, res, config, pixiv_client); serve_redirect(req, res, config, get_origin(req, config) + "/users/" + req.matches.str(1) + "/illustrations");
}); });
server.Get("/users/(\\d+)/illustrations", [&](const httplib::Request& req, httplib::Response& res) { server.Get("/users/(\\d+)/illustrations", [&](const httplib::Request& req, httplib::Response& res) {
user_illustrations_route(req, res, config, pixiv_client); user_illustrations_route(req, res, config, pixiv_client);

View File

@ -7,6 +7,5 @@ class PixivClient; // forward declaration from ../pixivclient.h
void home_route(const httplib::Request& req, httplib::Response& res, const Config& config); void home_route(const httplib::Request& req, httplib::Response& res, const Config& config);
void css_route(const httplib::Request& req, httplib::Response& res); void css_route(const httplib::Request& req, httplib::Response& res);
void users_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client);
void user_illustrations_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client); void user_illustrations_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client);
void artworks_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client); void artworks_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client);

View File

@ -1,27 +0,0 @@
#include "../routes.h"
#include "../../numberhelper.h"
#include "../../servehelper.h"
#include "../../pixivclient.h"
#include "common.h"
void users_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) {
uint64_t user_id = to_ull(req.matches[1].str());
User user;
try {
user = pixiv_client.get_user(user_id);
} 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;
}
serve(req, res, config, user.display_name + " (@" + user.username + ')', generate_user_header(user, config));
}