2019-06-17 17:35:47 -04:00
|
|
|
// <config-one>
|
2019-06-26 04:27:25 -04:00
|
|
|
use actix_files as fs;
|
|
|
|
use actix_web::http::header::{ContentDisposition, DispositionType};
|
2020-09-12 16:21:54 +01:00
|
|
|
use actix_web::{get, App, Error, HttpRequest, HttpServer};
|
2019-06-17 17:35:47 -04:00
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[get("/{filename:.*}")]
|
2019-12-29 03:36:24 +09:00
|
|
|
async fn index(req: HttpRequest) -> Result<fs::NamedFile, Error> {
|
2019-06-26 04:27:25 -04:00
|
|
|
let path: std::path::PathBuf = req.match_info().query("filename").parse().unwrap();
|
|
|
|
let file = fs::NamedFile::open(path)?;
|
|
|
|
Ok(file
|
|
|
|
.use_last_modified(true)
|
|
|
|
.set_content_disposition(ContentDisposition {
|
|
|
|
disposition: DispositionType::Attachment,
|
|
|
|
parameters: vec![],
|
|
|
|
}))
|
|
|
|
}
|
2019-06-17 17:35:47 -04:00
|
|
|
|
2020-09-12 16:21:54 +01:00
|
|
|
#[actix_web::main]
|
2019-12-29 03:36:24 +09:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2020-09-12 16:21:54 +01:00
|
|
|
HttpServer::new(|| App::new().service(index))
|
2022-02-26 03:56:24 +00:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-26 04:27:25 -04:00
|
|
|
.run()
|
2019-12-29 03:36:24 +09:00
|
|
|
.await
|
2019-06-26 04:27:25 -04:00
|
|
|
}
|
2019-06-17 17:35:47 -04:00
|
|
|
// </config-one>
|