diff --git a/src/vistas/download.rs b/src/vistas/download.rs index 97f25db..e9579b6 100644 --- a/src/vistas/download.rs +++ b/src/vistas/download.rs @@ -7,7 +7,11 @@ use tokio::fs::read_dir; use tokio_util::io::ReaderStream; use crate::lib::env_uploads_dir; -pub async fn get_file(axum::extract::Path(hash): axum::extract::Path) -> impl IntoResponse { +pub async fn get_file(axum::extract::Path(hash_with_ext): axum::extract::Path) -> impl IntoResponse { + // if it came with extension, extrat exten from hash + let fnamevec: Vec<&str> = hash_with_ext.split(".").collect(); + let hash = fnamevec[0].to_string(); + // find file from hash let (fpath, fname) = match find_file(hash).await { Ok(file) => file, diff --git a/src/vistas/upload.rs b/src/vistas/upload.rs index 6c0511d..419e91a 100644 --- a/src/vistas/upload.rs +++ b/src/vistas/upload.rs @@ -17,6 +17,7 @@ pub async fn upload(mut multipart: Multipart) -> Response { println!("Length of `{}` is {} bytes", name, data.len()); // tracing::debug!("Length of `{}` is {} bytes", name, data.len()); + let exten = filename.split(".").last().unwrap(); let fillo = randstr(); // directorio que aloxará o arquivo let pai = &fillo[0..1]; // agrupase por directorios co mesmo comezo (1ºchar) let path = format!("{}/{}/{}", env_uploads_dir(), pai, fillo); @@ -27,8 +28,12 @@ pub async fn upload(mut multipart: Multipart) -> Response { .expect("error creando directorios"); let mut file = File::create(dest).await.expect("error creando arquivo"); file.write_all(&data).await.expect("error gardando contido"); - - link = format!("{}/f/{}\n", env_base_url(), fillo); + + if exten == filename { + link = format!("{}/f/{}\n", env_base_url(), fillo); + } else { + link = format!("{}/f/{}.{}\n", env_base_url(), fillo, exten); + } } link.into_response()