insignificant changes

* renamed `run_tar_in_thread()` to `stream_tar_in_thread()`
* use `impl Responder` instead of `Result<HttpResponse>`
* add an `.unwrap()` to `StaticFiles::new()` (seems to be an upstream API change)
This commit is contained in:
Дамјан Георгиевски 2018-07-08 16:07:32 +02:00
parent 803ffc0c99
commit e9ef0d582e
2 changed files with 6 additions and 6 deletions

View file

@ -18,7 +18,7 @@ type Sender = futures::sync::mpsc::Sender<bytes::Bytes>;
type BlockingSender = futures::sink::Wait<Sender>;
pub fn run_tar_in_thread(path: PathBuf) -> Stream {
pub fn stream_tar_in_thread(path: PathBuf) -> Stream {
let (writer, stream) = StreamWriter::new(4 * 1024 * 1024);
thread::spawn(move || {

View file

@ -1,4 +1,4 @@
use actix_web::{error, fs, App, HttpRequest, HttpResponse, Result, http::Method};
use actix_web::{error, fs, App, HttpRequest, HttpResponse, Responder, http::Method};
use futures::Stream;
use percent_encoding::{utf8_percent_encode, DEFAULT_ENCODE_SET};
use htmlescape::encode_minimal as escape_html_entity;
@ -9,7 +9,7 @@ use std::path::PathBuf;
use std;
pub fn create_app() -> App {
let s = fs::StaticFiles::new(".").show_files_listing().files_listing_renderer(handle_directory);
let s = fs::StaticFiles::new(".").unwrap().show_files_listing().files_listing_renderer(handle_directory);
App::new()
.resource(r"/{tail:.*}.tar", |r| r.method(Method::GET).f(handle_tar))
.handler("/", s)
@ -56,15 +56,15 @@ fn handle_directory<'a, 'b>(
Ok(HttpResponse::Ok().content_type("text/html; charset=utf-8").body(body))
}
fn handle_tar(req: &HttpRequest) -> Result<HttpResponse> {
fn handle_tar(req: &HttpRequest) -> impl Responder {
let path: PathBuf = req.match_info().query("tail")?;
if !(path.is_dir()) {
return Err(error::ErrorBadRequest("not a directory"));
}
let stream = channel::run_tar_in_thread(path);
let stream = channel::stream_tar_in_thread(path);
let resp = HttpResponse::Ok()
.content_type("application/x-tar")
.streaming(stream.map_err(|_e| error::ErrorBadRequest("bad request")));
.streaming(stream.map_err(|_e| error::ErrorBadRequest("stream error")));
Ok(resp)
}