Skip to content

Commit

Permalink
Merge pull request #11 from kozakura913/main
Browse files Browse the repository at this point in the history
HTMLエスケープされた値を復号する
  • Loading branch information
kozakura913 authored Apr 28, 2024
2 parents 13e9d32 + fc3488e commit af28fd6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ html_parser = "0.7"
html-escape = "0.2"
urlencoding = "2.1.3"
encoding_rs = "0.8"
chrono = "0.4"

[profile.release]
strip = true
Expand Down
43 changes: 25 additions & 18 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ async fn get_file(
(client,config):(reqwest::Client,Arc<ConfigFile>),
axum::extract::Query(q):axum::extract::Query<RequestParams>,
)->axum::response::Response{
println!("{}\t{}\tlang:{:?}\tresponse_timeout:{:?}\tcontent_length_limit:{:?}\tuser_agent:{:?}",
chrono::Utc::now().to_rfc3339_opts(chrono::SecondsFormat::Millis, true),
q.url,
q.lang,
q.user_agent,
q.response_timeout,
q.content_length_limit,
);
if q.url.starts_with("coffee://"){
let mut headers=axum::http::HeaderMap::new();
headers.append("X-Proxy-Error","I'm a teapot".parse().unwrap());
Expand Down Expand Up @@ -294,52 +302,52 @@ async fn get_file(
("meta",att)=>{
match att.get("name").unwrap_or(&None).as_ref().map(|s|(
s.as_str(),
att.get("content").unwrap_or(&None).as_ref(),
att.get("content").unwrap_or(&None).as_ref().map(|s|html_escape::decode_html_entities(s)),
)){
Some(("msapplication-tooltip",Some(content))) => {
if resp.description.is_none(){//og:description優先
resp.description=Some(content.clone());
resp.description=Some(content.into());
}
},
Some(("application-name",Some(content))) => {
if resp.sitename.is_none(){//og:site_name優先
resp.sitename=Some(content.clone());
resp.sitename=Some(content.to_string());
}
if resp.title.is_none(){//og:title優先
resp.title=Some(content.clone());
resp.title=Some(content.to_string());
}
},
_=>{}
}
match att.get("property").unwrap_or(&None).as_ref().map(|s|(
s.as_str(),
att.get("content").unwrap_or(&None).as_ref(),
att.get("content").unwrap_or(&None).as_ref().map(|s|html_escape::decode_html_entities(s)),
)){
Some(("og:image",Some(content))) => {
resp.thumbnail=Some(content.clone());
resp.thumbnail=Some(content.into());
},
Some(("og:url",Some(content))) => {
resp.url=content.clone();
resp.url=content.into();
},
Some(("og:title",Some(content))) => {
resp.title=Some(content.clone());
resp.title=Some(content.into());
},
Some(("og:description",Some(content))) => {
resp.description=Some(content.clone());
resp.description=Some(content.into());
},
Some(("description",Some(content))) => {
resp.description=Some(content.clone());
resp.description=Some(content.into());
},
Some(("og:site_name",Some(content))) => {
resp.sitename=Some(content.clone());
resp.sitename=Some(content.into());
},
Some(("og:video:url",Some(content))) => {
if player.url.is_none(){//og:video:secure_url優先
player.url=Some(content.clone());
player.url=Some(content.into());
}
},
Some(("og:video:secure_url",Some(content))) => {
player.url=Some(content.clone());
player.url=Some(content.into());
},
Some(("og:video:width",Some(content))) => {
if let Ok(content)=content.parse::<f64>(){
Expand All @@ -357,24 +365,23 @@ async fn get_file(
("link",att)=>{
match att.get("rel").unwrap_or(&None).as_ref().map(|s|(
s.as_str(),
att.get("href").unwrap_or(&None).as_ref(),
att.get("href").unwrap_or(&None).as_ref().map(|s|html_escape::decode_html_entities(s)),
att.get("type").unwrap_or(&None).as_ref().map(|t|t.as_str()),
)){
Some(("shortcut icon",Some(href),_)) => {
if resp.icon.is_none(){//icon優先
resp.icon=Some(href.clone());
resp.icon=Some(href.into());
}
},
Some(("icon",Some(href),_)) => {
resp.icon=Some(href.clone());
resp.icon=Some(href.into());
},
Some(("apple-touch-icon",Some(href),_)) => {
if resp.thumbnail.is_none(){//og:image優先
resp.thumbnail=Some(href.clone());
resp.thumbnail=Some(href.into());
}
},
Some(("alternate",Some(href),Some("application/json+oembed"))) => {
let href=html_escape::decode_html_entities(&href);
let embed_res=if let Ok(mut href)=urlencoding::decode(&href){
if let Some(s)=solve_url(&href,&base_url,&base_url_str,&None,""){
href=Cow::Owned(s);
Expand Down

0 comments on commit af28fd6

Please sign in to comment.