2018-05-10 20:01:16 +02:00
|
|
|
use rocket::response::NamedFile;
|
|
|
|
use std::path::{Path, PathBuf};
|
|
|
|
|
2018-06-18 19:28:28 +02:00
|
|
|
macro_rules! may_fail {
|
|
|
|
($expr:expr, $template:expr, $msg:expr, | $res:ident | $block:block) => {
|
|
|
|
{
|
|
|
|
let res = $expr;
|
|
|
|
if res.is_some() {
|
|
|
|
let $res = res.unwrap();
|
|
|
|
$block
|
|
|
|
} else {
|
2018-06-18 19:44:18 +02:00
|
|
|
Template::render(concat!("errors/", $template), json!({
|
2018-06-18 19:28:28 +02:00
|
|
|
"error_message": $msg
|
|
|
|
}))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
($expr:expr, $msg:expr, | $res:ident | $block:block) => {
|
|
|
|
may_fail!($expr, "404", $msg, |$res| {
|
|
|
|
$block
|
|
|
|
})
|
|
|
|
};
|
|
|
|
($expr:expr, | $res:ident | $block:block) => {
|
|
|
|
may_fail!($expr, "", |$res| {
|
|
|
|
$block
|
|
|
|
})
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2018-04-23 12:54:37 +02:00
|
|
|
pub mod blogs;
|
2018-05-10 11:44:57 +02:00
|
|
|
pub mod comments;
|
2018-06-18 17:59:49 +02:00
|
|
|
pub mod errors;
|
2018-04-22 15:35:37 +02:00
|
|
|
pub mod instance;
|
2018-05-10 18:38:03 +02:00
|
|
|
pub mod likes;
|
2018-05-13 15:35:55 +02:00
|
|
|
pub mod notifications;
|
2018-04-23 16:25:39 +02:00
|
|
|
pub mod posts;
|
2018-05-19 11:51:10 +02:00
|
|
|
pub mod reshares;
|
2018-04-24 11:21:39 +02:00
|
|
|
pub mod session;
|
2018-04-22 20:13:12 +02:00
|
|
|
pub mod user;
|
2018-04-24 10:35:45 +02:00
|
|
|
pub mod well_known;
|
2018-05-10 20:01:16 +02:00
|
|
|
|
|
|
|
#[get("/static/<file..>")]
|
|
|
|
fn static_files(file: PathBuf) -> Option<NamedFile> {
|
|
|
|
NamedFile::open(Path::new("static/").join(file)).ok()
|
|
|
|
}
|