Thumbnail generation for iframely incompatible sources
This commit is contained in:
parent
80b3855829
commit
b52e91d3ad
1 changed files with 19 additions and 3 deletions
|
@ -185,6 +185,7 @@ pub fn fetch_pictshare(image_url: &str) -> Result<PictshareResponse, failure::Er
|
||||||
utf8_percent_encode(image_url, NON_ALPHANUMERIC)
|
utf8_percent_encode(image_url, NON_ALPHANUMERIC)
|
||||||
);
|
);
|
||||||
let text = isahc::get(&fetch_url)?.text()?;
|
let text = isahc::get(&fetch_url)?.text()?;
|
||||||
|
println!("--------------{}", text);
|
||||||
let res: PictshareResponse = serde_json::from_str(&text)?;
|
let res: PictshareResponse = serde_json::from_str(&text)?;
|
||||||
Ok(res)
|
Ok(res)
|
||||||
}
|
}
|
||||||
|
@ -198,8 +199,8 @@ fn fetch_iframely_and_pictshare_data(
|
||||||
Option<String>,
|
Option<String>,
|
||||||
) {
|
) {
|
||||||
// Fetch iframely data
|
// Fetch iframely data
|
||||||
let (iframely_title, iframely_description, iframely_thumbnail_url, iframely_html) = match url {
|
let (iframely_title, iframely_description, iframely_thumbnail_url, iframely_html) = match &url {
|
||||||
Some(url) => match fetch_iframely(&url) {
|
Some(url) => match fetch_iframely(url) {
|
||||||
Ok(res) => (res.title, res.description, res.thumbnail_url, res.html),
|
Ok(res) => (res.title, res.description, res.thumbnail_url, res.html),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
error!("iframely err: {}", e);
|
error!("iframely err: {}", e);
|
||||||
|
@ -218,7 +219,22 @@ fn fetch_iframely_and_pictshare_data(
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
None => match url {
|
||||||
|
Some(url) => match fetch_pictshare(&url) {
|
||||||
|
// Try to generate a small thumbnail if iframely is not supported
|
||||||
|
Ok(res) => {
|
||||||
|
let mut split_url: Vec<&str> = res.url.split("/").collect();
|
||||||
|
split_url.insert(split_url.len() - 1, "192");
|
||||||
|
Some(split_url.join("/"))
|
||||||
|
}
|
||||||
|
Err(e) => {
|
||||||
|
error!("pictshare err: {}", e);
|
||||||
|
None
|
||||||
|
}
|
||||||
|
},
|
||||||
None => None,
|
None => None,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
(
|
(
|
||||||
|
|
Loading…
Reference in a new issue