remove /jump.php track links

This commit is contained in:
2022-03-02 22:49:42 +08:00
parent ded0e77956
commit 41bc589050
5 changed files with 34 additions and 2 deletions

7
Cargo.lock generated
View File

@@ -1075,6 +1075,7 @@ dependencies = [
"reqwest",
"spin_on",
"tokio",
"urlparse",
"utf16string",
"winapi",
]
@@ -1702,6 +1703,12 @@ dependencies = [
"percent-encoding",
]
[[package]]
name = "urlparse"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "110352d4e9076c67839003c7788d8604e24dcded13e0b375af3efaa8cf468517"
[[package]]
name = "utf16string"
version = "0.2.0"

View File

@@ -16,12 +16,13 @@ html_parser = "0.6.2"
int-enum = { version = "0.4", optional = true }
lazy_static = "1.4"
json = "0.12"
utf16string = { version= "0.2", optional = true }
regex = "1"
reqwest = { version = "0.11", features = ["brotli", "deflate", "gzip", "rustls-tls", "socks", "stream"] }
RustyXML = "0.3"
spin_on = "0.1.1"
tokio = { version = "1.17", features = ["rt", "macros", "rt-multi-thread", "time"] }
urlparse = "0.7"
utf16string = { version= "0.2", optional = true }
[build-dependencies]
cmake = "0.1"

View File

@@ -11,6 +11,7 @@ extern crate lazy_static;
extern crate tokio;
extern crate regex;
extern crate reqwest;
extern crate urlparse;
#[cfg(feature = "utf16string")]
extern crate utf16string;
extern crate xml;

View File

@@ -1,4 +1,5 @@
use crate::gettext;
use crate::pixiv_link::remove_track;
use html_parser::Dom;
use html_parser::Node;
use std::collections::HashMap;
@@ -98,7 +99,8 @@ impl DescriptionParser {
if href.is_some() {
let href = href.unwrap();
if href.is_some() {
node.add_attr("href", href.as_ref().unwrap());
let link = remove_track(href.as_ref().unwrap());
node.add_attr("href", link.as_str());
}
}
}
@@ -171,4 +173,8 @@ fn test_parse_description() {
Some(String::from("a [a\n[bc](a.com)d](b.com)\ndata")),
parse_description("a <a href=\"b.com\">a<br/><a href=\"a.com\">bc</a>d</a><br>data")
);
assert_eq!(
Some(String::from("https://a.com")),
parse_description("<a href=\"/jump.php?https%3A%2F%2Fa.com\">https://a.com</a>")
)
}

View File

@@ -1,6 +1,7 @@
use crate::data::json::ToJson;
use json::JsonValue;
use regex::Regex;
use reqwest::IntoUrl;
use std::convert::TryInto;
lazy_static! {
@@ -98,3 +99,19 @@ impl TryInto<u64> for &PixivID {
}
}
}
pub fn remove_track<U: IntoUrl>(url: U) -> String {
let s = String::from(url.as_str());
let u = urlparse::urlparse(s.as_str());
let path = u.path.as_str();
if path.ends_with("/jump.php") {
if u.query.is_some() {
let q = u.query.as_ref().unwrap();
let re = urlparse::unquote(q);
if re.is_ok() {
return re.unwrap();
}
}
}
s
}