Skip Note attachments with type other than Document

This commit is contained in:
silverpill 2022-01-08 21:16:12 +00:00
parent d4ab05ce1f
commit de37f606e3
2 changed files with 13 additions and 4 deletions

View file

@ -23,7 +23,7 @@ pub struct Attachment {
pub attachment_type: String,
pub media_type: Option<String>,
pub url: String,
pub url: Option<String>,
}
#[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![];

View file

@ -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),