do some code cleanup

pull/3/head
neri 3 years ago
parent 594ca9d253
commit a92d7fe397

@ -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<NamedFile, Error> {
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)))

Loading…
Cancel
Save