Individually proxy custom emojis
This commit is contained in:
parent
c586de66ba
commit
902c9a6e42
@ -175,6 +175,7 @@ async fn main() -> tide::Result<()> {
|
|||||||
app.at("/vid/:id/:size/").get(proxy::video);
|
app.at("/vid/:id/:size/").get(proxy::video);
|
||||||
app.at("/img/:id/").get(proxy::image);
|
app.at("/img/:id/").get(proxy::image);
|
||||||
app.at("/thumb/:point/:id/").get(proxy::thumbnail);
|
app.at("/thumb/:point/:id/").get(proxy::thumbnail);
|
||||||
|
app.at("/emoji/:id/:name/").get(proxy::emoji);
|
||||||
|
|
||||||
// Browse user profile
|
// Browse user profile
|
||||||
app.at("/u/:name/").get(user::profile);
|
app.at("/u/:name/").get(user::profile);
|
||||||
|
@ -51,6 +51,13 @@ pub async fn thumbnail(req: Request<()>) -> tide::Result {
|
|||||||
request(url).await
|
request(url).await
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub async fn emoji(req: Request<()>) -> tide::Result {
|
||||||
|
let id = req.param("id").unwrap_or_default();
|
||||||
|
let name = req.param("name").unwrap_or_default();
|
||||||
|
let url = format!("https://emoji.redditmedia.com/{}/{}", id, name);
|
||||||
|
request(url).await
|
||||||
|
}
|
||||||
|
|
||||||
async fn request(url: String) -> tide::Result {
|
async fn request(url: String) -> tide::Result {
|
||||||
let http = surf::get(url).await.unwrap();
|
let http = surf::get(url).await.unwrap();
|
||||||
|
|
||||||
|
24
src/utils.rs
24
src/utils.rs
@ -188,27 +188,25 @@ pub fn format_url(url: &str) -> String {
|
|||||||
} else {
|
} else {
|
||||||
let domain = Url::parse(url).map(|f| f.domain().unwrap_or_default().to_owned()).unwrap_or_default();
|
let domain = Url::parse(url).map(|f| f.domain().unwrap_or_default().to_owned()).unwrap_or_default();
|
||||||
|
|
||||||
let capture = |regex: &str, format: &str| {
|
let capture = |regex: &str, format: &str, levels: i16| {
|
||||||
Regex::new(regex)
|
Regex::new(regex)
|
||||||
.map(|re| match re.captures(url) {
|
.map(|re| match re.captures(url) {
|
||||||
Some(caps) => [format, &caps[1], "/"].join(""),
|
Some(caps) => match levels {
|
||||||
|
1 => [format, &caps[1], "/"].join(""),
|
||||||
|
2 => [format, &caps[1], "/", &caps[2], "/"].join(""),
|
||||||
|
_ => String::new()
|
||||||
|
},
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
})
|
})
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
};
|
};
|
||||||
|
|
||||||
match domain.as_str() {
|
match domain.as_str() {
|
||||||
"v.redd.it" => {
|
"v.redd.it" => capture(r"https://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$))", "/vid/", 2),
|
||||||
let re = Regex::new(r"https://v\.redd\.it/(.*)/DASH_([0-9]{2,4}(\.mp4|$))").unwrap();
|
"i.redd.it" => capture(r"https://i\.redd\.it/(.*)", "/img/", 1),
|
||||||
|
"a.thumbs.redditmedia.com" => capture(r"https://a\.thumbs\.redditmedia\.com/(.*)", "/thumb/a/", 1),
|
||||||
match re.captures(url) {
|
"b.thumbs.redditmedia.com" => capture(r"https://b\.thumbs\.redditmedia\.com/(.*)", "/thumb/b/", 1),
|
||||||
Some(caps) => format!("/vid/{}/{}", &caps[1], &caps[2]),
|
"emoji.redditmedia.com" => capture(r"https://emoji\.redditmedia\.com/(.*)/(.*)", "/emoji/", 2),
|
||||||
None => String::new(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"i.redd.it" => capture(r"https://i\.redd\.it/(.*)", "/img/"),
|
|
||||||
"a.thumbs.redditmedia.com" => capture(r"https://a\.thumbs\.redditmedia\.com/(.*)", "/thumb/a/"),
|
|
||||||
"b.thumbs.redditmedia.com" => capture(r"https://b\.thumbs\.redditmedia\.com/(.*)", "/thumb/b/"),
|
|
||||||
_ => format!("/proxy/{}/", encode(url).as_str()),
|
_ => format!("/proxy/{}/", encode(url).as_str()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user