mirror of https://github.com/LemmyNet/lemmy.git
Fix video thumbnail generation (fixes #3484)
parent
255e695633
commit
ec9b8836ec
|
@ -59,14 +59,8 @@ pub async fn fetch_link_metadata(
|
||||||
let opengraph_data = extract_opengraph_data(&html_bytes, url)
|
let opengraph_data = extract_opengraph_data(&html_bytes, url)
|
||||||
.map_err(|e| info!("{e}"))
|
.map_err(|e| info!("{e}"))
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
let thumbnail = extract_thumbnail_from_opengraph_data(
|
let thumbnail =
|
||||||
url,
|
extract_thumbnail_from_opengraph_data(url, &opengraph_data, generate_thumbnail, context).await;
|
||||||
&opengraph_data,
|
|
||||||
&content_type,
|
|
||||||
generate_thumbnail,
|
|
||||||
context,
|
|
||||||
)
|
|
||||||
.await;
|
|
||||||
|
|
||||||
Ok(LinkMetadata {
|
Ok(LinkMetadata {
|
||||||
opengraph_data,
|
opengraph_data,
|
||||||
|
@ -158,23 +152,21 @@ fn extract_opengraph_data(html_bytes: &[u8], url: &Url) -> Result<OpenGraphData,
|
||||||
pub async fn extract_thumbnail_from_opengraph_data(
|
pub async fn extract_thumbnail_from_opengraph_data(
|
||||||
url: &Url,
|
url: &Url,
|
||||||
opengraph_data: &OpenGraphData,
|
opengraph_data: &OpenGraphData,
|
||||||
content_type: &Option<Mime>,
|
|
||||||
generate_thumbnail: bool,
|
generate_thumbnail: bool,
|
||||||
context: &LemmyContext,
|
context: &LemmyContext,
|
||||||
) -> Option<DbUrl> {
|
) -> Option<DbUrl> {
|
||||||
let is_image = content_type.as_ref().unwrap_or(&mime::TEXT_PLAIN).type_() == mime::IMAGE;
|
if generate_thumbnail {
|
||||||
if generate_thumbnail && is_image {
|
|
||||||
let image_url = opengraph_data
|
let image_url = opengraph_data
|
||||||
.image
|
.image
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(lemmy_db_schema::newtypes::DbUrl::inner)
|
.map(DbUrl::inner)
|
||||||
.unwrap_or(url);
|
.unwrap_or(url);
|
||||||
generate_pictrs_thumbnail(image_url, context)
|
generate_pictrs_thumbnail(image_url, context)
|
||||||
.await
|
.await
|
||||||
.ok()
|
.ok()
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
} else {
|
} else {
|
||||||
None
|
opengraph_data.image.clone()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue