fix: compat option to force document type
All checks were successful
/ build (push) Successful in 10m24s
All checks were successful
/ build (push) Successful in 10m24s
This commit is contained in:
parent
e6d6de4cc6
commit
d93034fbf1
2 changed files with 17 additions and 3 deletions
|
@ -129,8 +129,9 @@ pub struct SecurityConfig {
|
|||
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, serde_default::DefaultFromSerde)]
|
||||
pub struct CompatibilityConfig {
|
||||
#[serde_inline_default(true)]
|
||||
/// compatibility with almost everything: set image attachments as images
|
||||
pub fix_attachment_images_media_type: bool,
|
||||
/// compatibility with almost everything: set document type as image/video/audio according to
|
||||
/// mediaType, because almost all software sends us `Document` attachments
|
||||
pub fix_attachment_media_type: bool,
|
||||
|
||||
#[serde_inline_default(true)]
|
||||
/// compatibility with mastodon and misskey (and somewhat lemmy?): notify like receiver
|
||||
|
|
|
@ -88,6 +88,18 @@ impl Normalizer for crate::Context {
|
|||
if u == obj_image { continue };
|
||||
model.url = Set(self.cloaked(&u));
|
||||
}
|
||||
// TODO this is the third time we do this check... can we somehow centralize it?
|
||||
if self.cfg().compat.fix_attachment_media_type && model.document_type == Set(apb::DocumentType::Document) {
|
||||
let media_type = model.media_type.clone().take().unwrap_or_default();
|
||||
let (mime_kind, _mime_type) = media_type.split_once('/').unwrap_or_default();
|
||||
model.document_type = Set(match mime_kind {
|
||||
"image" => apb::DocumentType::Image,
|
||||
"video" => apb::DocumentType::Video,
|
||||
"audio" => apb::DocumentType::Audio,
|
||||
"text" => apb::DocumentType::Page,
|
||||
_ => apb::DocumentType::Document,
|
||||
});
|
||||
}
|
||||
model
|
||||
},
|
||||
Node::Link(l) => {
|
||||
|
@ -105,13 +117,14 @@ impl Normalizer for crate::Context {
|
|||
};
|
||||
|
||||
// in case we get both broken media_type and document_type, try to fix images with url
|
||||
// TODO is this still needed? above case with mediaType should solve most issues
|
||||
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 {
|
||||
if self.cfg().compat.fix_attachment_media_type {
|
||||
document_type = apb::DocumentType::Image;
|
||||
media_type = format!("image/{}", url.split('.').last().unwrap_or_default());
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue