From 84b5852aad17961dfa2cb6ea3351b9fa3244fe6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vojt=C4=9Bch=20Pej=C5=A1a?= Date: Thu, 28 Mar 2019 11:29:56 +0100 Subject: Fix file upload when used with random route. --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index f7d0b1b..7ae06bd 100644 --- a/src/main.rs +++ b/src/main.rs @@ -182,14 +182,20 @@ fn main() { /// Configures the Actix application fn configure_app(mut app: App) -> App { + let upload_route; let s = { let path = &app.state().path; let no_symlinks = app.state().no_symlinks; let random_route = app.state().random_route.clone(); let file_upload = app.state().file_upload.clone(); + upload_route = match app.state().random_route.clone() { + Some(random_route) => format!("/{}/upload", random_route), + None => format!("/upload"), + }; if path.is_file() { None } else { + let u_r = upload_route.clone(); Some( fs::StaticFiles::new(path) .expect("Couldn't create path") @@ -201,6 +207,7 @@ fn configure_app(mut app: App) -> App { no_symlinks, file_upload, random_route.clone(), + u_r.clone(), ) }), ) @@ -212,7 +219,7 @@ fn configure_app(mut app: App) -> App { // Allow file upload if app.state().file_upload { - app = app.resource("/upload", |r| { + app = app.resource(&upload_route, |r| { r.method(Method::POST).f(file_upload::upload_file) }); } -- cgit v1.2.3