diff --git a/crates/api_crud/src/post/create.rs b/crates/api_crud/src/post/create.rs index 4e519ce0d..89a710169 100644 --- a/crates/api_crud/src/post/create.rs +++ b/crates/api_crud/src/post/create.rs @@ -52,7 +52,7 @@ impl PerformCrud for CreatePost { // Fetch post links and pictrs cached image let data_url = data.url.as_ref(); let (metadata_res, pictrs_thumbnail) = - fetch_site_metadata_and_pictrs_data(context.client(), data_url).await?; + fetch_site_metadata_and_pictrs_data(context.client(), data_url).await; let (embed_title, embed_description, embed_html) = metadata_res .map(|u| (u.title, u.description, u.html)) .unwrap_or((None, None, None)); diff --git a/crates/api_crud/src/post/update.rs b/crates/api_crud/src/post/update.rs index b31feaee3..9e0b54ed8 100644 --- a/crates/api_crud/src/post/update.rs +++ b/crates/api_crud/src/post/update.rs @@ -52,7 +52,7 @@ impl PerformCrud for EditPost { // Fetch post links and Pictrs cached image let data_url = data.url.as_ref(); let (metadata_res, pictrs_thumbnail) = - fetch_site_metadata_and_pictrs_data(context.client(), data_url).await?; + fetch_site_metadata_and_pictrs_data(context.client(), data_url).await; let (embed_title, embed_description, embed_html) = metadata_res .map(|u| (u.title, u.description, u.html)) .unwrap_or((None, None, None)); diff --git a/crates/apub/src/objects/post.rs b/crates/apub/src/objects/post.rs index 024ab6f1a..67e161eed 100644 --- a/crates/apub/src/objects/post.rs +++ b/crates/apub/src/objects/post.rs @@ -189,7 +189,7 @@ impl FromApub for Post { let thumbnail_url: Option = page.image.clone().map(|i| i.url); let (metadata_res, pictrs_thumbnail) = if let Some(url) = &page.url { - fetch_site_metadata_and_pictrs_data(context.client(), Some(url)).await? + fetch_site_metadata_and_pictrs_data(context.client(), Some(url)).await } else { (None, thumbnail_url) }; diff --git a/crates/utils/src/request.rs b/crates/utils/src/request.rs index bb6056217..a4825e4d8 100644 --- a/crates/utils/src/request.rs +++ b/crates/utils/src/request.rs @@ -120,7 +120,7 @@ pub(crate) struct PictrsFile { pub(crate) async fn fetch_pictrs( client: &Client, image_url: &Url, -) -> Result, LemmyError> { +) -> Result { if let Some(pictrs_url) = Settings::get().pictrs_url { is_image_content_type(client, image_url).await?; @@ -138,12 +138,12 @@ pub(crate) async fn fetch_pictrs( .map_err(|e| RecvError(e.to_string()))?; if response.msg == "ok" { - Ok(Some(response)) + Ok(response) } else { Err(anyhow!("{}", &response.msg).into()) } } else { - Ok(None) + Err(anyhow!("pictrs_url not set up in config").into()) } } @@ -151,7 +151,7 @@ pub(crate) async fn fetch_pictrs( pub async fn fetch_site_metadata_and_pictrs_data( client: &Client, url: Option<&Url>, -) -> Result<(Option, Option), LemmyError> { +) -> (Option, Option) { match &url { Some(url) => { // Fetch metadata @@ -162,22 +162,19 @@ pub async fn fetch_site_metadata_and_pictrs_data( // Fetch pictrs thumbnail let pictrs_hash = match &metadata_option { Some(metadata_res) => match &metadata_res.image { + // Metadata, with image + // Try to generate a small thumbnail if there's a full sized one from post-links Some(metadata_image) => fetch_pictrs(client, metadata_image) .await - // Ignore the error, just return None - .unwrap_or(None) .map(|r| r.files[0].file.to_owned()), - // Try to generate a small thumbnail if there's a full sized one from post-links + // Metadata, but no image None => fetch_pictrs(client, url) .await - // Ignore the error, just return None - .unwrap_or(None) .map(|r| r.files[0].file.to_owned()), }, + // No metadata, try to fetch the URL as an image None => fetch_pictrs(client, url) .await - // Ignore the error, just return None - .unwrap_or(None) .map(|r| r.files[0].file.to_owned()), }; @@ -191,11 +188,12 @@ pub async fn fetch_site_metadata_and_pictrs_data( )) .ok() }) + .ok() .flatten(); - Ok((metadata_option, pictrs_thumbnail)) + (metadata_option, pictrs_thumbnail) } - None => Ok((None, None)), + None => (None, None), } }