From b52e91d3ada48f5e9a479e4137e8b31e63626425 Mon Sep 17 00:00:00 2001 From: Andre Vallestero Date: Wed, 6 May 2020 20:40:36 -0400 Subject: [PATCH] Thumbnail generation for iframely incompatible sources --- server/src/lib.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index 79a1437e7..1c24f0b4c 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, + }, }; (