From a92d7fe39758fa5536cc0048b0375a3afe9f7348 Mon Sep 17 00:00:00 2001 From: neri Date: Tue, 14 Jul 2020 17:53:43 +0200 Subject: [PATCH] do some code cleanup --- src/main.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/main.rs b/src/main.rs index 1a1d107..e071a12 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,7 +28,7 @@ const UPLOAD_HTML: &str = include_str!("../template/upload.html"); const VIEW_HTML: &str = include_str!("../template/view.html"); async fn index() -> Result { - Ok(NamedFile::open("static/index.html") + Ok(NamedFile::open("./static/index.html") .map_err(|_| error::ErrorNotFound(""))? .disable_content_disposition()) } @@ -154,35 +154,32 @@ struct Config { #[actix_rt::main] async fn main() -> std::io::Result<()> { - env::set_var( - "RUST_LOG", - env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()), - ); + if env::var("RUST_LOG").is_err() { + env::set_var("RUST_LOG", "info"); + } env_logger::init(); let pool: PgPool = setup_db().await; - let config = Config { server_url: env::var("SERVER_URL").unwrap_or_else(|_| "http://localhost:8000".to_owned()), files_dir: PathBuf::from(env::var("FILES_DIR").unwrap_or_else(|_| "./files".to_owned())), }; - fs::create_dir_all(&config.files_dir) .await .expect("could not create directory for storing files"); + let (sender, receiver) = channel(8); log::info!("omnomnom"); - let (send, recv) = channel(1); task::spawn(deleter::delete_old_files( - recv, + receiver, pool.clone(), config.files_dir.clone(), )); let db = web::Data::new(pool); - let send = web::Data::new(send); - let max_bytes: usize = env::var("UPLOAD_MAX_BYTES") + let sender = web::Data::new(sender); + let upload_max_bytes: usize = env::var("UPLOAD_MAX_BYTES") .ok() .and_then(|variable| variable.parse().ok()) .unwrap_or(8_388_608); @@ -193,8 +190,8 @@ async fn main() -> std::io::Result<()> { App::new() .wrap(middleware::Logger::default()) .app_data(db.clone()) - .app_data(send.clone()) - .app_data(Bytes::configure(|cfg| cfg.limit(max_bytes))) + .app_data(sender.clone()) + .app_data(Bytes::configure(|cfg| cfg.limit(upload_max_bytes))) .data(config.clone()) .service(web::resource("/").route(web::get().to(index))) .service(web::resource("/upload").route(web::post().to(upload)))