master
rasul 5 years ago
parent f115e72dad
commit 5401bcc268

@ -43,11 +43,13 @@ impl Paste {
lang: "Plain Text".into(), lang: "Plain Text".into(),
}) })
} else { } else {
Err(Box::new(Error::new(ErrorKind::Other, "couldn't generate hash"))) Err(Box::new(Error::new(
ErrorKind::Other,
"couldn't generate hash",
)))
} }
} }
pub fn from_form(form: HashMap<String, String>, salt: String) -> Result<Self> { pub fn from_form(form: HashMap<String, String>, salt: String) -> Result<Self> {
let dt = Utc::now(); let dt = Utc::now();
let harsh = HarshBuilder::new().salt(salt).init()?; let harsh = HarshBuilder::new().salt(salt).init()?;

@ -27,19 +27,14 @@ pub fn get(mut state: State) -> Box<HandlerFuture> {
match Paste::from_file(path) { match Paste::from_file(path) {
Ok(paste) => { Ok(paste) => {
let res = create_response( let res = create_response(&state, StatusCode::OK, mime::TEXT_PLAIN, paste.text);
&state,
StatusCode::OK,
mime::TEXT_PLAIN,
paste.text,
);
future::ok((state, res)) future::ok((state, res))
}, }
Err(e) => { Err(e) => {
let io_error = std::io::Error::new(std::io::ErrorKind::Other, e.description()); let io_error = std::io::Error::new(std::io::ErrorKind::Other, e.description());
future::err((state, io_error.into_handler_error())) future::err((state, io_error.into_handler_error()))
}, }
} }
}) })
} }

@ -43,20 +43,19 @@ pub fn put(mut state: State) -> Box<HandlerFuture> {
future::ok((state, res)) future::ok((state, res))
} }
}, }
Err(e) => { Err(e) => {
let err = Error::new(ErrorKind::Other, e.description()); let err = Error::new(ErrorKind::Other, e.description());
future::err((state, err.into_handler_error())) future::err((state, err.into_handler_error()))
} }
} }
}, }
Err(e) => future::err((state, e.into_handler_error())), Err(e) => future::err((state, e.into_handler_error())),
} }
}) })
}) })
} }
pub fn post(mut state: State) -> Box<HandlerFuture> { pub fn post(mut state: State) -> Box<HandlerFuture> {
Box::new({ Box::new({
Body::take_from(&mut state).concat2().then(|body| { Body::take_from(&mut state).concat2().then(|body| {
@ -86,12 +85,7 @@ pub fn post(mut state: State) -> Box<HandlerFuture> {
future::ok((state, res)) future::ok((state, res))
} else { } else {
let res = create_response( let res = create_response(&state, StatusCode::OK, mime::TEXT_PLAIN, "ERR");
&state,
StatusCode::OK,
mime::TEXT_PLAIN,
"ERR"
);
future::ok((state, res)) future::ok((state, res))
} }

@ -8,7 +8,7 @@ lazy_static! {
let mut syntaxes: Vec<String> = Vec::new(); let mut syntaxes: Vec<String> = Vec::new();
for syntax in syntax_set.syntaxes() { for syntax in syntax_set.syntaxes() {
if ! syntax.hidden { if !syntax.hidden {
syntaxes.push(syntax.name.clone()); syntaxes.push(syntax.name.clone());
} }
} }

Loading…
Cancel
Save