From e9ef0d582ecf7ca83fd43e8c0e668f2e0f3cf278 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=98=D0=B0=D0=BD=20=D0=93=D0=B5=D0=BE?= =?UTF-8?q?=D1=80=D0=B3=D0=B8=D0=B5=D0=B2=D1=81=D0=BA=D0=B8?= Date: Sun, 8 Jul 2018 16:07:32 +0200 Subject: [PATCH] insignificant changes * renamed `run_tar_in_thread()` to `stream_tar_in_thread()` * use `impl Responder` instead of `Result` * add an `.unwrap()` to `StaticFiles::new()` (seems to be an upstream API change) --- src/channel.rs | 2 +- src/web.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/channel.rs b/src/channel.rs index e748294..9741b6c 100644 --- a/src/channel.rs +++ b/src/channel.rs @@ -18,7 +18,7 @@ type Sender = futures::sync::mpsc::Sender; type BlockingSender = futures::sink::Wait; -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 || { diff --git a/src/web.rs b/src/web.rs index bdec225..7d0b473 100644 --- a/src/web.rs +++ b/src/web.rs @@ -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 { +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) }