From: Andre Vallestero Date: Thu, 7 May 2020 00:40:36 +0000 (-0400) Subject: Thumbnail generation for iframely incompatible sources X-Git-Url: http://these/git/%22https:/lemmy.ml/u/Liwott/%24%7Bargs.pageFn.prev%7D?a=commitdiff_plain;h=d96c66ba9f35b3646aada116665d50f99e49ca37;p=lemmy.git Thumbnail generation for iframely incompatible sources --- diff --git a/server/src/lib.rs b/server/src/lib.rs index 79a1437e..1c24f0b4 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -185,6 +185,7 @@ pub fn fetch_pictshare(image_url: &str) -> Result, ) { // Fetch iframely data - let (iframely_title, iframely_description, iframely_thumbnail_url, iframely_html) = match url { - Some(url) => match fetch_iframely(&url) { + let (iframely_title, iframely_description, iframely_thumbnail_url, iframely_html) = match &url { + Some(url) => match fetch_iframely(url) { Ok(res) => (res.title, res.description, res.thumbnail_url, res.html), Err(e) => { error!("iframely err: {}", e); @@ -218,7 +219,22 @@ fn fetch_iframely_and_pictshare_data( None } }, - 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, + }, }; (