diff --git a/routes/artworks.cpp b/routes/artworks.cpp index 23a220a..968c5f5 100644 --- a/routes/artworks.cpp +++ b/routes/artworks.cpp @@ -15,6 +15,7 @@ static inline Element generate_illust_tags(const Illust& illust); static inline bool is_true(const std::string& str); static inline std::string time_to_string(time_t time); +static inline std::string proxy_pixiv_url(const httplib::Request& req, const Config& config, blankie::murl::Url url); void artworks_route(const httplib::Request& req, httplib::Response& res, const Config& config, PixivClient& pixiv_client) { uint64_t illust_id = to_ull(req.matches.str(1)); @@ -123,7 +124,7 @@ static inline std::vector parse_description_line(const http blankie::murl::Url url(sm.str(0)); std::string url_str = url.is_host_equal("pixiv.net") || url.is_host_equal("www.pixiv.net") - ? proxy_url(get_origin(req, config), std::move(url)) + ? proxy_pixiv_url(req, config, std::move(url)) : url.to_string(); nodes.push_back(Element("a", {{"href", url_str}}, {url_str})); @@ -197,3 +198,14 @@ static inline std::string time_to_string(time_t time) { return std::string(str, len); } + +static inline std::string proxy_pixiv_url(const httplib::Request& req, const Config& config, blankie::murl::Url url) { + if (url.path.size() >= 4 && url.path.starts_with("/en/")) { + url.path.erase(0, 3); + } else if (url.path.size() == 3 && url.path == "/en") { + url.path = '/'; + } + + // TODO strip the lang query parameter + return proxy_url(get_origin(req, config), std::move(url)); +}