fix upload without filename

This commit is contained in:
neri 2022-11-24 00:04:09 +01:00
parent 16ba5f025e
commit f9de6e5164
3 changed files with 15 additions and 12 deletions

2
Cargo.lock generated
View File

@ -416,7 +416,7 @@ dependencies = [
[[package]]
name = "datatrash"
version = "2.0.2"
version = "2.0.3"
dependencies = [
"actix-files",
"actix-governor",

View File

@ -1,6 +1,6 @@
[package]
name = "datatrash"
version = "2.0.2"
version = "2.0.3"
authors = ["neri"]
edition = "2021"

View File

@ -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<String>)>,
) -> Result<HttpResponse, Error> {
let (id, name) = path.into_inner();
pub async fn uploaded(req: HttpRequest) -> Result<HttpResponse, Error> {
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")