allow user provided mime types
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
parent
acfe506f51
commit
c2f93e5aea
16
src/main.rs
16
src/main.rs
@ -10,8 +10,8 @@ mod chacha_io;
|
|||||||
mod pgp;
|
mod pgp;
|
||||||
mod snippet;
|
mod snippet;
|
||||||
|
|
||||||
use crate::snippet::*;
|
|
||||||
use crate::pgp::KnownKeys;
|
use crate::pgp::KnownKeys;
|
||||||
|
use crate::snippet::*;
|
||||||
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
|
||||||
use chacha_io::{ChaChaReader, ChaChaWriter};
|
use chacha_io::{ChaChaReader, ChaChaWriter};
|
||||||
use chrono::*;
|
use chrono::*;
|
||||||
@ -30,9 +30,8 @@ use std::io;
|
|||||||
use std::io::prelude::*;
|
use std::io::prelude::*;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use std::sync::Mutex;
|
||||||
|
|
||||||
#[cfg(not(debug_assertions))]
|
#[cfg(not(debug_assertions))]
|
||||||
const STORAGE_DIR: &str = "/snips";
|
const STORAGE_DIR: &str = "/snips";
|
||||||
@ -100,7 +99,15 @@ fn handle(req: &mut Request) -> IronResult<Response> {
|
|||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Method::Get, Some(id)) => {
|
(Method::Get, Some(path)) => {
|
||||||
|
let (id, mime) = {
|
||||||
|
let mut parts = path.split(".");
|
||||||
|
(
|
||||||
|
parts.next().unwrap().to_string(),
|
||||||
|
parts.next().flat_map(|format| format.parse::<Mime>().ok()),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
let mime = mime.unwrap_or("application/text".parse().unwrap());
|
||||||
let att = storage.open(&id).map(|snip| snip.contents()).map(|res| {
|
let att = storage.open(&id).map(|snip| snip.contents()).map(|res| {
|
||||||
Response::with(
|
Response::with(
|
||||||
match res.map(|text| (iron::status::Ok, text)).map_err(|err| {
|
match res.map(|text| (iron::status::Ok, text)).map_err(|err| {
|
||||||
@ -111,6 +118,7 @@ fn handle(req: &mut Request) -> IronResult<Response> {
|
|||||||
Err(e) => (iron::status::InternalServerError, e),
|
Err(e) => (iron::status::InternalServerError, e),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
.set(mime)
|
||||||
});
|
});
|
||||||
Ok(att.unwrap_or(Response::with((iron::status::NotFound, "Not here sry"))))
|
Ok(att.unwrap_or(Response::with((iron::status::NotFound, "Not here sry"))))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user