Limit number of attachments in remote posts
This commit is contained in:
parent
0ce0cd15c3
commit
b53a1298a2
2 changed files with 7 additions and 1 deletions
|
@ -46,6 +46,7 @@ fn get_note_author_id(object: &Object) -> Result<String, ValidationError> {
|
|||
}
|
||||
|
||||
const CONTENT_MAX_SIZE: usize = 100000;
|
||||
const ATTACHMENTS_MAX_NUM: usize = 15;
|
||||
|
||||
fn parse_object_url(value: &JsonValue) -> Result<String, ConversionError> {
|
||||
let object_url = match value {
|
||||
|
@ -186,6 +187,11 @@ pub async fn handle_note(
|
|||
file_name,
|
||||
attachment.media_type.or(media_type),
|
||||
));
|
||||
// Stop downloading if limit is reached
|
||||
if downloaded.len() >= ATTACHMENTS_MAX_NUM {
|
||||
log::warn!("too many attachments");
|
||||
break;
|
||||
};
|
||||
};
|
||||
for (file_name, media_type) in downloaded {
|
||||
let db_attachment = create_attachment(
|
||||
|
|
|
@ -257,7 +257,7 @@ impl PostCreateData {
|
|||
let content_trimmed = content_safe.trim();
|
||||
if content_trimmed.is_empty() {
|
||||
return Err(ValidationError("post can not be empty"));
|
||||
}
|
||||
};
|
||||
self.content = content_trimmed.to_string();
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue