Set limit on the size of remote media files

This commit is contained in:
silverpill 2022-08-18 22:50:40 +00:00
parent 4dc94ed39b
commit e51f5fa3bb

View file

@ -79,6 +79,8 @@ async fn send_request(
Ok(data)
}
const FILE_MAX_SIZE: usize = 1024 * 1024 * 10;
pub async fn fetch_file(
url: &str,
output_dir: &Path,
@ -86,6 +88,9 @@ pub async fn fetch_file(
let client = build_client()?;
let response = client.get(url).send().await?;
let file_data = response.bytes().await?;
if file_data.len() > FILE_MAX_SIZE {
return Err(FetchError::OtherError("file is too large"));
};
let (file_name, media_type) = save_file(file_data.to_vec(), output_dir, None)?;
Ok((file_name, media_type))
}