diff --git a/src/main.rs b/src/main.rs index acb4127..2d98eca 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,24 +12,19 @@ mod snippet; use crate::pgp::KnownKeys; use crate::snippet::*; -use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; -use chacha_io::{ChaChaReader, ChaChaWriter}; -use chrono::*; -use core::cell::RefCell; + use iron::method::Method; use iron::modifiers::Redirect; use iron::prelude::*; use iron::url::Url; -use rand::Rng; -use sha2::{Digest, Sha256}; -use std::borrow::BorrowMut; -use std::convert::TryInto; -use std::fs; -use std::fs::File; + +use iron::mime::Mime; +use sha2::Digest; + use std::io; use std::io::prelude::*; use std::iter::Iterator; -use std::path::{Path, PathBuf}; +use std::path::Path; use std::sync::Arc; use std::sync::Mutex; @@ -104,10 +99,12 @@ fn handle(req: &mut Request) -> IronResult { let mut parts = path.split("."); ( parts.next().unwrap().to_string(), - parts.next().flat_map(|format| format.parse::().ok()), + Some(parts.collect::>().join("/")) + .filter(|s| s.len() > 0) + .and_then(|format| format.parse::().ok()), ) }; - let mime = mime.unwrap_or("application/text".parse().unwrap()); + let mime = mime.unwrap_or("text/plain".parse().unwrap()); let att = storage.open(&id).map(|snip| snip.contents()).map(|res| { Response::with( match res.map(|text| (iron::status::Ok, text)).map_err(|err| {