apply formatter

This commit is contained in:
neri 2020-08-03 01:12:42 +02:00
parent 180bc08cc5
commit e3a7c5329e
1 changed files with 19 additions and 6 deletions

View File

@ -4,7 +4,13 @@ mod multipart;
use actix_files::{Files, NamedFile}; use actix_files::{Files, NamedFile};
use actix_multipart::Multipart; use actix_multipart::Multipart;
use actix_web::{error, http::header::{ContentDisposition, DispositionParam, DispositionType}, middleware, web::{self, Bytes}, App, Error, FromRequest, HttpRequest, HttpResponse, HttpServer}; use actix_web::{
error,
http::header::{ContentDisposition, DispositionParam, DispositionType},
middleware,
web::{self, Bytes},
App, Error, FromRequest, HttpRequest, HttpResponse, HttpServer,
};
use async_std::{ use async_std::{
fs, fs,
path::PathBuf, path::PathBuf,
@ -75,8 +81,7 @@ async fn upload(
async fn uploaded(id: web::Path<String>, req: web::HttpRequest) -> Result<HttpResponse, Error> { async fn uploaded(id: web::Path<String>, req: web::HttpRequest) -> Result<HttpResponse, Error> {
let url = req.url_for("file", &[id.as_str()])?; let url = req.url_for("file", &[id.as_str()])?;
let upload_html = UPLOAD_HTML let upload_html = UPLOAD_HTML.replace("{url}", url.as_str());
.replace("{url}", url.as_str());
Ok(HttpResponse::Ok() Ok(HttpResponse::Ok()
.content_type("text/html") .content_type("text/html")
.body(upload_html)) .body(upload_html))
@ -140,9 +145,13 @@ fn get_db_url() -> String {
url += "@"; url += "@";
} }
url += env::var("DATABASE_HOST").unwrap_or_else(|_| "localhost".to_string()).as_str(); url += env::var("DATABASE_HOST")
.unwrap_or_else(|_| "localhost".to_string())
.as_str();
url += "/"; url += "/";
url += env::var("DATABASE_NAME").unwrap_or_else(|_| "datatrash".to_string()).as_str(); url += env::var("DATABASE_NAME")
.unwrap_or_else(|_| "datatrash".to_string())
.as_str();
url.to_string() url.to_string()
}); });
@ -215,7 +224,11 @@ async fn main() -> std::io::Result<()> {
.service(web::resource("/").route(web::get().to(index))) .service(web::resource("/").route(web::get().to(index)))
.service(web::resource("/upload").route(web::post().to(upload))) .service(web::resource("/upload").route(web::post().to(upload)))
.service(web::resource("/upload/{id}").route(web::get().to(uploaded))) .service(web::resource("/upload/{id}").route(web::get().to(uploaded)))
.service(web::resource("/file/{id}").name("file").route(web::get().to(download))) .service(
web::resource("/file/{id}")
.name("file")
.route(web::get().to(download)),
)
.service(Files::new("/static", "static").disable_content_disposition()) .service(Files::new("/static", "static").disable_content_disposition())
} }
}) })