fix: skip double lemmy image, not any attachment
some lemmy posts which had a single link attachment would get that attachment stripped for this fix. now it should keep those while still stripping the doubled image
This commit is contained in:
parent
68b217e648
commit
5800f39c67
1 changed files with 58 additions and 52 deletions
|
@ -72,19 +72,9 @@ impl Normalizer for crate::Context {
|
|||
.await?;
|
||||
}
|
||||
|
||||
// TODO this check is a bit disgusting but lemmy for some incomprehensible reason sends us
|
||||
// the same image twice: once in `image` and once as `attachment`. you may say "well just
|
||||
// check if url is the same" and i absolutely do but lemmy is 10 steps forwards and it sends
|
||||
// the same image twice with two distinct links. checkmate fedi developers!!!!!
|
||||
// so basically i don't want to clutter my timeline with double images, nor fetch every image
|
||||
// that comes from lemmy (we cloak and lazy-load) just to dedupe it...
|
||||
let attachments = object.attachment().flat();
|
||||
if !(
|
||||
self.cfg().compat.skip_single_attachment_if_image_is_set
|
||||
&& object_model.image.is_some()
|
||||
&& attachments.len() == 1
|
||||
) {
|
||||
let obj_image = object_model.image.clone().unwrap_or_default();
|
||||
let attachments_len = attachments.len();
|
||||
for attachment in attachments {
|
||||
let attachment_model = match attachment {
|
||||
Node::Empty => continue,
|
||||
|
@ -105,15 +95,32 @@ impl Normalizer for crate::Context {
|
|||
if url == obj_image { continue };
|
||||
let mut media_type = l.media_type().unwrap_or("link".to_string());
|
||||
let mut document_type = apb::DocumentType::Page;
|
||||
if self.cfg().compat.fix_attachment_images_media_type
|
||||
&& [".jpg", ".jpeg", ".png", ".webp", ".bmp"] // TODO more image types???
|
||||
let mut is_image = false;
|
||||
if [".jpg", ".jpeg", ".png", ".webp", ".bmp"] // TODO more image types???
|
||||
.iter()
|
||||
.any(|x| url.ends_with(x))
|
||||
{
|
||||
is_image = true;
|
||||
if self.cfg().compat.fix_attachment_images_media_type {
|
||||
document_type = apb::DocumentType::Image;
|
||||
media_type = format!("image/{}", url.split('.').last().unwrap_or_default());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// TODO this check is a bit disgusting but lemmy for some incomprehensible reason sends us
|
||||
// the same image twice: once in `image` and once as `attachment`. you may say "well just
|
||||
// check if url is the same" and i absolutely do but lemmy is 10 steps forwards and it sends
|
||||
// the same image twice with two distinct links. checkmate fedi developers!!!!!
|
||||
// so basically i don't want to clutter my timeline with double images, nor fetch every image
|
||||
// that comes from lemmy (we cloak and lazy-load) just to dedupe it...
|
||||
if is_image
|
||||
&& self.cfg().compat.skip_single_attachment_if_image_is_set
|
||||
&& object_model.image.is_some()
|
||||
&& attachments_len == 1
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
crate::model::attachment::ActiveModel {
|
||||
internal: sea_orm::ActiveValue::NotSet,
|
||||
url: Set(self.cloaked(&url)),
|
||||
|
@ -128,7 +135,6 @@ impl Normalizer for crate::Context {
|
|||
.exec(tx)
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
for tag in object.tag().flat() {
|
||||
match tag {
|
||||
|
|
Loading…
Reference in a new issue