From d96c66ba9f35b3646aada116665d50f99e49ca37 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 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, + }, }; ( -- 2.44.1