From de37f606e3892f0e82825b3ff97679f7de43ce7e Mon Sep 17 00:00:00 2001 From: silverpill Date: Sat, 8 Jan 2022 21:16:12 +0000 Subject: [PATCH] Skip Note attachments with type other than Document --- src/activitypub/activity.rs | 4 ++-- src/activitypub/receiver.rs | 13 +++++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/activitypub/activity.rs b/src/activitypub/activity.rs index ccc4796..559280b 100644 --- a/src/activitypub/activity.rs +++ b/src/activitypub/activity.rs @@ -23,7 +23,7 @@ pub struct Attachment { pub attachment_type: String, pub media_type: Option, - pub url: String, + pub url: Option, } #[derive(Deserialize, Serialize)] @@ -180,7 +180,7 @@ pub fn create_note( name: None, attachment_type: DOCUMENT.to_string(), media_type, - url, + url: Some(url), } }).collect(); let mut primary_audience = vec![]; diff --git a/src/activitypub/receiver.rs b/src/activitypub/receiver.rs index bb77a2b..bd2d8f4 100644 --- a/src/activitypub/receiver.rs +++ b/src/activitypub/receiver.rs @@ -226,9 +226,18 @@ pub async fn process_note( let mut downloaded = vec![]; let output_dir = config.media_dir(); for attachment in list { - let (file_name, media_type) = fetch_attachment(&attachment.url, &output_dir).await + if attachment.attachment_type != DOCUMENT { + log::warn!( + "skipping attachment of type {}", + attachment.attachment_type, + ); + continue; + }; + let attachment_url = attachment.url + .ok_or(ValidationError("attachment URL is missing"))?; + let (file_name, media_type) = fetch_attachment(&attachment_url, &output_dir).await .map_err(|_| ValidationError("failed to fetch attachment"))?; - log::info!("downloaded attachment {}", attachment.url); + log::info!("downloaded attachment {}", attachment_url); downloaded.push(( file_name, attachment.media_type.or(media_type),