Use usize type for file sizes
This commit is contained in:
parent
c26fc9235d
commit
6c6eb731f9
4 changed files with 7 additions and 5 deletions
|
@ -19,7 +19,7 @@ use crate::models::profiles::{
|
|||
},
|
||||
};
|
||||
|
||||
const ACTOR_IMAGE_MAX_SIZE: u64 = 5 * 1000 * 1000; // 5 MB
|
||||
const ACTOR_IMAGE_MAX_SIZE: usize = 5 * 1000 * 1000; // 5 MB
|
||||
|
||||
async fn fetch_actor_images(
|
||||
instance: &Instance,
|
||||
|
|
|
@ -108,7 +108,7 @@ pub async fn fetch_file(
|
|||
instance: &Instance,
|
||||
url: &str,
|
||||
maybe_media_type: Option<&str>,
|
||||
file_max_size: u64,
|
||||
file_max_size: usize,
|
||||
output_dir: &Path,
|
||||
) -> Result<(String, Option<String>), FetchError> {
|
||||
let client = build_client(instance)?;
|
||||
|
@ -116,12 +116,14 @@ pub async fn fetch_file(
|
|||
build_request(instance, client, Method::GET, url);
|
||||
let response = request_builder.send().await?.error_for_status()?;
|
||||
if let Some(file_size) = response.content_length() {
|
||||
let file_size: usize = file_size.try_into()
|
||||
.expect("value should be within bounds");
|
||||
if file_size > file_max_size {
|
||||
return Err(FetchError::OtherError("file is too large"));
|
||||
};
|
||||
};
|
||||
let file_data = response.bytes().await?;
|
||||
if file_data.len() > file_max_size as usize {
|
||||
if file_data.len() > file_max_size {
|
||||
return Err(FetchError::OtherError("file is too large"));
|
||||
};
|
||||
let maybe_media_type = maybe_media_type
|
||||
|
|
|
@ -142,7 +142,7 @@ fn get_note_visibility(
|
|||
Visibility::Direct
|
||||
}
|
||||
|
||||
const ATTACHMENT_MAX_SIZE: u64 = 20 * 1000 * 1000;
|
||||
const ATTACHMENT_MAX_SIZE: usize = 20 * 1000 * 1000; // 20 MB
|
||||
|
||||
fn is_gnu_social_link(author_id: &str, attachment: &Attachment) -> bool {
|
||||
if !author_id.contains("/index.php/user/") {
|
||||
|
|
|
@ -2,7 +2,7 @@ use crate::errors::ValidationError;
|
|||
use crate::utils::html::clean_html_strict;
|
||||
|
||||
pub const ATTACHMENTS_MAX_NUM: usize = 15;
|
||||
pub const EMOJI_MAX_SIZE: u64 = 250 * 1000; // 250 kB
|
||||
pub const EMOJI_MAX_SIZE: usize = 250 * 1000; // 250 kB
|
||||
pub const EMOJI_MEDIA_TYPES: [&str; 2] = [
|
||||
"image/gif",
|
||||
"image/png",
|
||||
|
|
Loading…
Reference in a new issue