fix: skip attachments with url == image

This commit is contained in:
əlemi 2024-08-11 13:58:24 +02:00
parent 5481299140
commit 2d92f9c355
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -73,6 +73,7 @@ impl Normalizer for crate::Context {
.await?; .await?;
} }
let obj_image = object_model.image.clone().unwrap_or_default();
for attachment in object.attachment().flat() { for attachment in object.attachment().flat() {
let attachment_model = match attachment { let attachment_model = match attachment {
Node::Empty => continue, Node::Empty => continue,
@ -83,12 +84,14 @@ impl Normalizer for crate::Context {
Node::Object(o) => { Node::Object(o) => {
let mut model = AP::attachment_q(o.as_document()?, object_model.internal, None)?; let mut model = AP::attachment_q(o.as_document()?, object_model.internal, None)?;
if let Set(u) | Unchanged(u) = model.url { if let Set(u) | Unchanged(u) = model.url {
if u == obj_image { continue };
model.url = Set(self.cloaked(&u)); model.url = Set(self.cloaked(&u));
} }
model model
}, },
Node::Link(l) => { Node::Link(l) => {
let url = l.href().unwrap_or_default(); let url = l.href().unwrap_or_default();
if url == obj_image { continue };
let mut media_type = l.media_type().unwrap_or("link").to_string(); let mut media_type = l.media_type().unwrap_or("link").to_string();
let mut document_type = apb::DocumentType::Page; let mut document_type = apb::DocumentType::Page;
if self.cfg().compat.fix_attachment_images_media_type if self.cfg().compat.fix_attachment_images_media_type