From d96c66ba9f35b3646aada116665d50f99e49ca37 Mon Sep 17 00:00:00 2001 From: Andre Vallestero Date: Wed, 6 May 2020 20:40:36 -0400 Subject: [PATCH 1/6] 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, + }, }; ( From 243dda543cff0015132f8f0cc464a21a4162b096 Mon Sep 17 00:00:00 2001 From: Andre Vallestero Date: Wed, 6 May 2020 20:46:00 -0400 Subject: [PATCH 2/6] Removed debug line --- server/src/lib.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index 1c24f0b4..f7d2b0e9 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -185,7 +185,6 @@ pub fn fetch_pictshare(image_url: &str) -> Result 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(); + let mut split_url: Vec<&str> = res.url.split('/').collect(); split_url.insert(split_url.len() - 1, "192"); Some(split_url.join("/")) } From bc8ad12b04a501bf670cc541b20282a791a3aac4 Mon Sep 17 00:00:00 2001 From: Andre Vallestero Date: Thu, 7 May 2020 21:26:08 -0400 Subject: [PATCH 3/6] Added externally hosted UI thumbnail support --- ui/src/components/post-listing.tsx | 33 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index d0efa043..36a1e282 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -150,9 +150,9 @@ export class PostListing extends Component { let post = this.props.post; return ( ); @@ -163,6 +163,8 @@ export class PostListing extends Component { if (isImage(post.url)) { if (post.url.includes('pictshare')) { return pictshareImage(post.url, thumbnail); + } else if (post.thumbnail_url) { + return pictshareImage(post.thumbnail_url, thumbnail); } else { return post.url; } @@ -542,8 +544,9 @@ export class PostListing extends Component { } > @@ -586,8 +589,9 @@ export class PostListing extends Component { } > @@ -618,8 +622,9 @@ export class PostListing extends Component { data-tippy-content={i18n.t('view_source')} > @@ -639,8 +644,9 @@ export class PostListing extends Component { } > @@ -657,8 +663,9 @@ export class PostListing extends Component { } > From ffcbb7613e96b96f1a15963816106ba6c4c42943 Mon Sep 17 00:00:00 2001 From: Andre Vallestero Date: Thu, 7 May 2020 21:30:23 -0400 Subject: [PATCH 4/6] Added additional check for pictshare thumbnail --- ui/src/components/post-listing.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index 36a1e282..c1480f79 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -163,7 +163,10 @@ export class PostListing extends Component { if (isImage(post.url)) { if (post.url.includes('pictshare')) { return pictshareImage(post.url, thumbnail); - } else if (post.thumbnail_url) { + } else if ( + post.thumbnail_url && + post.thumbnail_url.includes('pictshare') + ) { return pictshareImage(post.thumbnail_url, thumbnail); } else { return post.url; From 38381ba2878f481dbba387cced3f3ac693a33fd3 Mon Sep 17 00:00:00 2001 From: Andre Vallestero Date: Thu, 7 May 2020 21:33:47 -0400 Subject: [PATCH 5/6] Removed hardcoded thumbnail value --- server/src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/server/src/lib.rs b/server/src/lib.rs index f7d2b0e9..5566ca69 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -222,11 +222,7 @@ fn fetch_iframely_and_pictshare_data( 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("/")) - } + Ok(res) => Some(res.url), Err(e) => { error!("pictshare err: {}", e); None From 9155469e8aab1bd2963f09332c0a6075808a09ee Mon Sep 17 00:00:00 2001 From: Andre Vallestero Date: Mon, 11 May 2020 11:29:35 -0400 Subject: [PATCH 6/6] Removed redundant erroneous check --- ui/src/components/post-listing.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ui/src/components/post-listing.tsx b/ui/src/components/post-listing.tsx index c1480f79..36a1e282 100644 --- a/ui/src/components/post-listing.tsx +++ b/ui/src/components/post-listing.tsx @@ -163,10 +163,7 @@ export class PostListing extends Component { if (isImage(post.url)) { if (post.url.includes('pictshare')) { return pictshareImage(post.url, thumbnail); - } else if ( - post.thumbnail_url && - post.thumbnail_url.includes('pictshare') - ) { + } else if (post.thumbnail_url) { return pictshareImage(post.thumbnail_url, thumbnail); } else { return post.url;