|
|
|
@ -17,7 +17,7 @@ use lemmy_db_schema::{
|
|
|
|
|
community::{Community, CommunityModerator, CommunityUpdateForm},
|
|
|
|
|
community_block::CommunityBlock,
|
|
|
|
|
email_verification::{EmailVerification, EmailVerificationForm},
|
|
|
|
|
images::RemoteImage,
|
|
|
|
|
images::{ImageDetails, RemoteImage},
|
|
|
|
|
instance::Instance,
|
|
|
|
|
instance_block::InstanceBlock,
|
|
|
|
|
local_site::LocalSite,
|
|
|
|
@ -1012,6 +1012,7 @@ pub async fn process_markdown(
|
|
|
|
|
|
|
|
|
|
if context.settings().pictrs_config()?.image_mode() == PictrsImageMode::ProxyAllImages {
|
|
|
|
|
let (text, links) = markdown_rewrite_image_links(text);
|
|
|
|
|
RemoteImage::create(&mut context.pool(), links.clone()).await?;
|
|
|
|
|
|
|
|
|
|
// Create images and image detail rows
|
|
|
|
|
for link in links {
|
|
|
|
@ -1021,7 +1022,7 @@ pub async fn process_markdown(
|
|
|
|
|
let proxied =
|
|
|
|
|
build_proxied_image_url(&link, &context.settings().get_protocol_and_hostname())?;
|
|
|
|
|
let details_form = details.build_image_details_form(&proxied);
|
|
|
|
|
RemoteImage::create(&mut context.pool(), &details_form).await?;
|
|
|
|
|
ImageDetails::create(&mut context.pool(), &details_form).await?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Ok(text)
|
|
|
|
@ -1057,13 +1058,15 @@ async fn proxy_image_link_internal(
|
|
|
|
|
if link.domain() == Some(&context.settings().hostname) {
|
|
|
|
|
Ok(link.into())
|
|
|
|
|
} else if image_mode == PictrsImageMode::ProxyAllImages {
|
|
|
|
|
RemoteImage::create(&mut context.pool(), vec![link.clone()]).await?;
|
|
|
|
|
|
|
|
|
|
let proxied = build_proxied_image_url(&link, &context.settings().get_protocol_and_hostname())?;
|
|
|
|
|
// This should fail softly, since pictrs might not even be running
|
|
|
|
|
let details_res = fetch_pictrs_proxied_image_details(&link, context).await;
|
|
|
|
|
|
|
|
|
|
if let Ok(details) = details_res {
|
|
|
|
|
let details_form = details.build_image_details_form(&proxied);
|
|
|
|
|
RemoteImage::create(&mut context.pool(), &details_form).await?;
|
|
|
|
|
ImageDetails::create(&mut context.pool(), &details_form).await?;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Ok(proxied.into())
|
|
|
|
@ -1209,7 +1212,7 @@ mod tests {
|
|
|
|
|
assert!(
|
|
|
|
|
RemoteImage::validate(&mut context.pool(), remote_image.into())
|
|
|
|
|
.await
|
|
|
|
|
.is_err()
|
|
|
|
|
.is_ok()
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|