hash con extension, para cando descargan con wget sin --content-disposition

This commit is contained in:
serxoz 2022-10-28 15:25:08 +02:00
parent 4e02baaaad
commit f4fcb2db40
2 changed files with 12 additions and 3 deletions

View File

@ -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<String>) -> impl IntoResponse {
pub async fn get_file(axum::extract::Path(hash_with_ext): axum::extract::Path<String>) -> 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,

View File

@ -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);
@ -28,7 +29,11 @@ pub async fn upload(mut multipart: Multipart) -> Response {
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()