1 parent
a238ff5e23
commit
93762fe9ef
65 files changed
+5420
-2792
No files matched your search
@@ -14,8 +14,6 @@ use crate::config::AppConfig;
|
||||
use crate::db;
|
||||
use crate::error::AppError;
|
||||
|
||||
/// Maximum attachment file size: 25 MB.
|
||||
const MAX_ATTACHMENT_SIZE: usize = 25 * 1024 * 1024;
|
||||
const STALE_PART_MAX_AGE: Duration = Duration::from_secs(24 * 60 * 60);
|
||||
|
||||
async fn cleanup_stale_upload_parts(dir: &Path) {
|
||||
@@ -92,6 +90,7 @@ pub async fn upload_attachment(
|
||||
cleanup_stale_upload_parts(&att_dir).await;
|
||||
|
||||
let mut uploaded = Vec::new();
|
||||
let max_attachment_size = config.max_attachment_size_bytes();
|
||||
|
||||
while let Some(mut field) = multipart
|
||||
.next_field()
|
||||
@@ -124,12 +123,12 @@ pub async fn upload_attachment(
|
||||
};
|
||||
let Some(chunk) = chunk else { break };
|
||||
size = size.saturating_add(chunk.len());
|
||||
if size > MAX_ATTACHMENT_SIZE {
|
||||
if size > max_attachment_size {
|
||||
drop(file);
|
||||
let _ = tokio::fs::remove_file(&part_path).await;
|
||||
return Err(AppError::BadRequest(format!(
|
||||
"File '{}' exceeds maximum size of 25 MB",
|
||||
filename
|
||||
"File '{}' exceeds maximum size of {} MiB",
|
||||
filename, config.max_attachment_size_mb
|
||||
)));
|
||||
}
|
||||
if let Err(e) = file.write_all(&chunk).await {
|
||||
|
||||
Reference in new issue
Block a user