Simplify pastebin retrieve handler.

This commit is contained in:
Sergio Benitez 2016-12-09 21:01:30 -08:00
parent a818976b08
commit b72af317f1
1 changed files with 3 additions and 4 deletions

View File

@ -11,8 +11,7 @@ use std::fs::File;
use std::path::Path; use std::path::Path;
use rocket::Data; use rocket::Data;
use rocket::response::{content, Failure}; use rocket::response::content;
use rocket::http::StatusCode::NotFound;
use paste_id::PasteID; use paste_id::PasteID;
@ -30,9 +29,9 @@ fn upload(paste: Data) -> io::Result<content::Plain<String>> {
} }
#[get("/<id>")] #[get("/<id>")]
fn retrieve(id: PasteID) -> Result<content::Plain<File>, Failure> { fn retrieve(id: PasteID) -> Option<content::Plain<File>> {
let filename = format!("upload/{id}", id = id); let filename = format!("upload/{id}", id = id);
File::open(&filename).map(|f| content::Plain(f)).map_err(|_| Failure(NotFound)) File::open(&filename).map(|f| content::Plain(f)).ok()
} }
#[get("/")] #[get("/")]