parent
9aa23233dd
commit
278deff6da
|
@ -241,20 +241,29 @@ static inline void preprocess_link(const httplib::Request& req, const std::strin
|
||||||
const lxb_char_t* cls_c = lxb_dom_element_class(element, &cls_c_len);
|
const lxb_char_t* cls_c = lxb_dom_element_class(element, &cls_c_len);
|
||||||
std::string cls = cls_c ? std::string(reinterpret_cast<const char*>(cls_c), cls_c_len) : "";
|
std::string cls = cls_c ? std::string(reinterpret_cast<const char*>(cls_c), cls_c_len) : "";
|
||||||
|
|
||||||
CurlUrl href_url;
|
try {
|
||||||
href_url.set(CURLUPART_URL, get_origin(req));
|
CurlUrl href_url;
|
||||||
href_url.set(CURLUPART_PATH, std::string(href_url.get(CURLUPART_PATH).get()) + req.path);
|
href_url.set(CURLUPART_URL, get_origin(req));
|
||||||
href_url.set(CURLUPART_URL, href);
|
href_url.set(CURLUPART_PATH, std::string(href_url.get(CURLUPART_PATH).get()) + req.path);
|
||||||
CurlUrl instance_url_base;
|
href_url.set(CURLUPART_URL, href);
|
||||||
instance_url_base.set(CURLUPART_SCHEME, "https");
|
|
||||||
instance_url_base.set(CURLUPART_HOST, domain_name);
|
|
||||||
// .mention is used in note and posts
|
|
||||||
// Instance base is used for link fields
|
|
||||||
if (std::regex_search(cls, mention_class_re) || starts_with(href_url, instance_url_base)) {
|
|
||||||
// Proxy this instance's URLs to Coyote
|
|
||||||
href = proxy_mastodon_url(req, std::move(href));
|
|
||||||
|
|
||||||
lxb_dom_element_set_attribute(element, reinterpret_cast<const lxb_char_t*>("href"), 4, reinterpret_cast<const lxb_char_t*>(href.data()), href.size());
|
CurlUrl instance_url_base;
|
||||||
|
instance_url_base.set(CURLUPART_SCHEME, "https");
|
||||||
|
instance_url_base.set(CURLUPART_HOST, domain_name);
|
||||||
|
|
||||||
|
// .mention is used in note and posts
|
||||||
|
// Instance base is used for link fields
|
||||||
|
if (std::regex_search(cls, mention_class_re) || starts_with(href_url, instance_url_base)) {
|
||||||
|
// Proxy this instance's URLs to Coyote
|
||||||
|
href = proxy_mastodon_url(req, std::move(href));
|
||||||
|
|
||||||
|
lxb_dom_element_set_attribute(element, reinterpret_cast<const lxb_char_t*>("href"), 4, reinterpret_cast<const lxb_char_t*>(href.data()), href.size());
|
||||||
|
}
|
||||||
|
} catch (const CurlUrlException& e) {
|
||||||
|
// example: <a href=""></a> on eldritch.cafe/about
|
||||||
|
if (e.code != CURLUE_MALFORMED_INPUT) {
|
||||||
|
throw;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (should_fix_link(element, cls)) {
|
if (should_fix_link(element, cls)) {
|
||||||
|
|
Loading…
Reference in New Issue