Proxying custom_thumbnail. Fixed logic for update.

custom_thumbnails
Dessalines 2024-02-12 11:53:37 -05:00
parent 4d1df6f573
commit 4fbe71ef31
2 changed files with 16 additions and 3 deletions

View File

@ -89,7 +89,10 @@ pub async fn create_post(
// Fetch post links and pictrs cached image // Fetch post links and pictrs cached image
let metadata = fetch_link_metadata_opt(url.as_ref(), true, &context).await; let metadata = fetch_link_metadata_opt(url.as_ref(), true, &context).await;
let url = proxy_image_link_opt_apub(url, &context).await?; let url = proxy_image_link_opt_apub(url, &context).await?;
let thumbnail_url = custom_thumbnail.map(Into::into).or(metadata.thumbnail); let thumbnail_url = proxy_image_link_opt_apub(custom_thumbnail, &context)
.await?
.map(Into::into)
.or(metadata.thumbnail);
// Only need to check if language is allowed in case user set it explicitly. When using default // Only need to check if language is allowed in case user set it explicitly. When using default
// language, it already only returns allowed languages. // language, it already only returns allowed languages.

View File

@ -73,23 +73,33 @@ pub async fn update_post(
} }
// Fetch post links and thumbnail if url was updated // Fetch post links and thumbnail if url was updated
let (embed_title, embed_description, embed_video_url, thumbnail_url) = match &url { let (embed_title, embed_description, embed_video_url, metadata_thumbnail) = match &url {
Some(url) => { Some(url) => {
let metadata = fetch_link_metadata(url, true, &context).await?; let metadata = fetch_link_metadata(url, true, &context).await?;
( (
Some(metadata.opengraph_data.title), Some(metadata.opengraph_data.title),
Some(metadata.opengraph_data.description), Some(metadata.opengraph_data.description),
Some(metadata.opengraph_data.embed_video_url), Some(metadata.opengraph_data.embed_video_url),
Some(custom_thumbnail.map(Into::into).or(metadata.thumbnail)), Some(metadata.thumbnail),
) )
} }
_ => Default::default(), _ => Default::default(),
}; };
let url = match url { let url = match url {
Some(url) => Some(proxy_image_link_opt_apub(Some(url), &context).await?), Some(url) => Some(proxy_image_link_opt_apub(Some(url), &context).await?),
_ => Default::default(), _ => Default::default(),
}; };
let custom_thumbnail = match custom_thumbnail {
Some(custom_thumbnail) => {
Some(proxy_image_link_opt_apub(Some(custom_thumbnail), &context).await?)
}
_ => Default::default(),
};
let thumbnail_url = custom_thumbnail.or(metadata_thumbnail);
let language_id = data.language_id; let language_id = data.language_id;
CommunityLanguage::is_allowed_community_language( CommunityLanguage::is_allowed_community_language(
&mut context.pool(), &mut context.pool(),