From 43378c5bb3149f3e8c71eacfb48b93ac9250d09a Mon Sep 17 00:00:00 2001 From: Nutomic Date: Fri, 15 Mar 2024 13:41:16 +0100 Subject: [PATCH] Fix video thumbnail generation (fixes #3484) (#4539) * Fix video thumbnail generation (fixes #3484) * fix test --- crates/api_common/src/request.rs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/crates/api_common/src/request.rs b/crates/api_common/src/request.rs index aaae7f866..c17d96a61 100644 --- a/crates/api_common/src/request.rs +++ b/crates/api_common/src/request.rs @@ -59,14 +59,8 @@ pub async fn fetch_link_metadata( let opengraph_data = extract_opengraph_data(&html_bytes, url) .map_err(|e| info!("{e}")) .unwrap_or_default(); - let thumbnail = extract_thumbnail_from_opengraph_data( - url, - &opengraph_data, - &content_type, - generate_thumbnail, - context, - ) - .await; + let thumbnail = + extract_thumbnail_from_opengraph_data(url, &opengraph_data, generate_thumbnail, context).await; Ok(LinkMetadata { opengraph_data, @@ -158,23 +152,21 @@ fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> Result, generate_thumbnail: bool, context: &LemmyContext, ) -> Option { - let is_image = content_type.as_ref().unwrap_or(&mime::TEXT_PLAIN).type_() == mime::IMAGE; - if generate_thumbnail && is_image { + if generate_thumbnail { let image_url = opengraph_data .image .as_ref() - .map(lemmy_db_schema::newtypes::DbUrl::inner) + .map(DbUrl::inner) .unwrap_or(url); generate_pictrs_thumbnail(image_url, context) .await .ok() .map(Into::into) } else { - None + opengraph_data.image.clone() } } @@ -363,7 +355,7 @@ mod tests { Some(mime::TEXT_HTML_UTF_8.to_string()), sample_res.content_type ); - assert_eq!(None, sample_res.thumbnail); + assert!(sample_res.thumbnail.is_some()); } // #[test]