Skip to content

Commit

Permalink
Log errors and use fallback during thumbnail generation (ref #5196)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Jan 3, 2025
1 parent c034229 commit d92e7a8
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions crates/api_common/src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use reqwest::{
};
use reqwest_middleware::ClientWithMiddleware;
use serde::{Deserialize, Serialize};
use tracing::info;
use tracing::{info, warn};
use url::Url;
use urlencoding::encode;
use webpage::HTML;
Expand Down Expand Up @@ -173,15 +173,23 @@ pub async fn generate_post_link_metadata(
metadata.opengraph_data.image.clone()
};

// Attempt to generate a thumbnail depending on the instance settings. Either by proxying,
// storing image persistently in pict-rs or returning the remote url directly as thumbnail.
let thumbnail_url = if let (false, Some(url)) = (is_image_post, custom_thumbnail) {
proxy_image_link(url, &context).await.ok()
} else if let (true, Some(url)) = (allow_generate_thumbnail, image_url) {
proxy_image_link(url.clone(), &context)
.await
.map_err(|e| warn!("Failed to proxy thumbnail: {e}"))
.ok()
.or(Some(url.into()))
} else if let (true, Some(url)) = (allow_generate_thumbnail, image_url.clone()) {
generate_pictrs_thumbnail(&url, &context)
.await
.map_err(|e| warn!("Failed to generate thumbnail: {e}"))
.ok()
.map(Into::into)
.or(image_url)
} else {
metadata.opengraph_data.image.clone()
image_url.clone()
};

let form = PostUpdateForm {
Expand Down

0 comments on commit d92e7a8

Please sign in to comment.