From f9de6e51645d082592d3942a88502f3c59cd398b Mon Sep 17 00:00:00 2001 From: neri Date: Thu, 24 Nov 2022 00:04:09 +0100 Subject: [PATCH] fix upload without filename --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/upload.rs | 23 +++++++++++++---------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1ad8562..5ce5a24 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -416,7 +416,7 @@ dependencies = [ [[package]] name = "datatrash" -version = "2.0.2" +version = "2.0.3" dependencies = [ "actix-files", "actix-governor", diff --git a/Cargo.toml b/Cargo.toml index 385f9be..a49bf15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "datatrash" -version = "2.0.2" +version = "2.0.3" authors = ["neri"] edition = "2021" diff --git a/src/upload.rs b/src/upload.rs index bd2584e..925a67a 100644 --- a/src/upload.rs +++ b/src/upload.rs @@ -55,9 +55,9 @@ pub async fn upload( "{} create new file {} (valid_till: {}, content_type: {}, delete_on_download: {})", req.connection_info().realip_remote_addr().unwrap_or("-"), file_id, + upload_config.valid_till, upload_config.content_type, - upload_config.delete_on_download, - upload_config.valid_till + upload_config.delete_on_download ); expiry_watch_sender.send(()).await.unwrap(); @@ -145,17 +145,20 @@ fn get_redirect_url(id: &str, name: Option<&str>) -> String { } } -pub async fn uploaded( - req: HttpRequest, - path: web::Path<(String, Option)>, -) -> Result { - let (id, name) = path.into_inner(); +pub async fn uploaded(req: HttpRequest) -> Result { + let id = req.match_info().query("id"); + let name = req + .match_info() + .get("name") + .map(urlencoding::decode) + .transpose() + .map_err(|_| error::ErrorBadRequest("name is invalid utf-8"))?; let upload_html = if name.is_some() { UPLOAD_SHORT_HTML - .replace("{link}", &get_file_url(&req, &id, name.as_deref())) - .replace("{shortlink}", &get_file_url(&req, &id, None)) + .replace("{link}", &get_file_url(&req, id, name.as_deref())) + .replace("{shortlink}", &get_file_url(&req, id, None)) } else { - UPLOAD_HTML.replace("{link}", &get_file_url(&req, &id, name.as_deref())) + UPLOAD_HTML.replace("{link}", &get_file_url(&req, id, name.as_deref())) }; Ok(HttpResponse::Ok() .content_type("text/html")