aboutsummaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs37
1 files changed, 34 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs
index f662a73..0ca2fdf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,5 +1,6 @@
#![feature(proc_macro_hygiene)]
+use actix_web::http::Method;
use actix_web::{fs, middleware, server, App};
use clap::crate_version;
use simplelog::{Config, LevelFilter, TermLogger};
@@ -13,6 +14,7 @@ mod archive;
mod args;
mod auth;
mod errors;
+mod file_upload;
mod listing;
mod renderer;
@@ -42,6 +44,12 @@ pub struct MiniserveConfig {
/// Enable random route generation
pub random_route: Option<String>,
+
+ /// Enable file upload
+ pub file_upload: bool,
+
+ /// Enable upload to override existing files
+ pub overwrite_files: bool,
}
fn main() {
@@ -174,19 +182,33 @@ fn main() {
/// Configures the Actix application
fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> {
+ 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;
+ upload_route = match app.state().random_route.clone() {
+ Some(random_route) => format!("/{}/upload", random_route),
+ None => "/upload".to_string(),
+ };
if path.is_file() {
None
} else {
+ let u_r = upload_route.clone();
Some(
fs::StaticFiles::new(path)
.expect("Couldn't create path")
.show_files_listing()
.files_listing_renderer(move |dir, req| {
- listing::directory_listing(dir, req, no_symlinks, random_route.clone())
+ listing::directory_listing(
+ dir,
+ req,
+ no_symlinks,
+ file_upload,
+ random_route.clone(),
+ u_r.clone(),
+ )
}),
)
}
@@ -196,8 +218,17 @@ fn configure_app(app: App<MiniserveConfig>) -> App<MiniserveConfig> {
let full_route = format!("/{}", random_route);
if let Some(s) = s {
- // Handle directories
- app.handler(&full_route, s)
+ if app.state().file_upload {
+ // Allow file upload
+ app.resource(&upload_route, |r| {
+ r.method(Method::POST).f(file_upload::upload_file)
+ })
+ // Handle directories
+ .handler(&full_route, s)
+ } else {
+ // Handle directories
+ app.handler(&full_route, s)
+ }
} else {
// Handle single files
app.resource(&full_route, |r| r.f(listing::file_handler))