diff --git a/src/api/upload.rs b/src/api/upload.rs index 56e9d3d..fcd8fa4 100644 --- a/src/api/upload.rs +++ b/src/api/upload.rs @@ -154,7 +154,7 @@ pub async fn upload_image( }; let dir_path = format!("uploads/{}/{}/{}", year, month, day); - let file_name = format!("{}.{ }.{}", now.format("%H%M%S"), uuid, ext); + let file_name = format!("{}.{}.{}", now.format("%H%M%S"), uuid, ext); let file_path = format!("{}/{}", dir_path, file_name); let url_path = format!("/uploads/{}/{}/{}/{}", year, month, day, file_name); @@ -189,4 +189,16 @@ pub async fn upload_image( }))) } +#[cfg(test)] +mod tests { + #[test] + fn filename_format_no_spaces() { + let now_str = "120000"; + let uuid = "abc-123"; + let ext = "jpg"; + let file_name = format!("{}.{}.{}", now_str, uuid, ext); + assert!(!file_name.contains(' '), "filename should not contain spaces: got '{}'", file_name); + } +} +