diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2022-09-12 12:19:39 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2022-09-12 12:19:39 +0000 |
| commit | af90ce3578cc46045d96938c9193f4ab8b9faccc (patch) | |
| tree | 2f8e732504a46edfb8965692243b006de3c5ee44 /src | |
| parent | 1e9f99b092346f4153fb5880b274778ce1195e6d (diff) | |
Use an uploads endpoint path
Diffstat (limited to 'src')
| -rw-r--r-- | src/config.rs | 3 | ||||
| -rw-r--r-- | src/files.rs | 11 |
2 files changed, 9 insertions, 5 deletions
diff --git a/src/config.rs b/src/config.rs index 5783656..fd85d91 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,6 @@ +// TODO: Everything here must be a std::env + pub static PAGE_LIMIT: i64 = 20; pub const MAX_UPLOAD_FILE_SIZE: u64 = 1024 * 1024; // 1 MB pub const SAVE_FILE_BASE_PATH: &str = "./uploads"; +pub const UPLOADS_ENDPOINT: &str = "http://localhost:3000/uploads"; diff --git a/src/files.rs b/src/files.rs index b88a5b7..bcda6ab 100644 --- a/src/files.rs +++ b/src/files.rs @@ -1,4 +1,4 @@ -use crate::config::SAVE_FILE_BASE_PATH; +use crate::config::{SAVE_FILE_BASE_PATH, UPLOADS_ENDPOINT}; use crate::errors::AppError; use axum::extract::Multipart; @@ -9,7 +9,7 @@ pub async fn upload( mut multipart: Multipart, allowed_extensions: Vec<&str>, ) -> Result<String, AppError> { - let mut save_filename = String::new(); + let mut uploaded_file = String::new(); if let Some(file) = multipart.next_field().await.unwrap() { let content_type = file.content_type().unwrap().to_string(); @@ -26,7 +26,8 @@ pub async fn upload( { let rnd = (random::<f32>() * 1000000000 as f32) as i32; - save_filename = format!("{}/{}.{}", SAVE_FILE_BASE_PATH, rnd, ext_name); + let save_filename = format!("{}/{}.{}", SAVE_FILE_BASE_PATH, rnd, ext_name); + uploaded_file = format!("{}/{}.{}", UPLOADS_ENDPOINT, rnd, ext_name); let data = file.bytes().await.unwrap(); @@ -36,8 +37,8 @@ pub async fn upload( } } - if !save_filename.is_empty() { - return Ok(save_filename); + if !uploaded_file.is_empty() { + return Ok(uploaded_file); } Err(AppError::BadRequest( |
