From 22f5a47425dc677294b6ae9ebf7ffe949e9dc903 Mon Sep 17 00:00:00 2001 From: Vika Date: Sun, 9 May 2021 16:51:24 +0300 Subject: Added a frontend to the application. TODO: Login, alternative themes, built-in Micropub capabilities when logged in --- src/lib.rs | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index c422fea..949b9ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,12 +1,9 @@ -#[cfg(debug_assertions)] -use log::info; -#[cfg(debug_assertions)] -use serde::Deserialize; use tide::{Request, Response}; mod database; mod indieauth; mod micropub; +mod frontend; use crate::indieauth::IndieAuthMiddleware; use crate::micropub::{get_handler,post_handler}; @@ -26,15 +23,6 @@ type App = tide::Server>; static MICROPUB_CLIENT: &[u8] = include_bytes!("./index.html"); -#[cfg(debug_assertions)] -#[derive(Deserialize)] -struct Mf2JsonQuery { - url: String, - limit: usize, - user: Option, - after: Option -} - fn equip_app(mut app: App) -> App where Storage: database::Storage + Send + Sync + Clone @@ -44,30 +32,9 @@ where app.at("/micropub/client").get(|_: Request<_>| async move { Ok(Response::builder(200).body(MICROPUB_CLIENT).content_type("text/html").build()) }); - #[cfg(debug_assertions)] - info!("Outfitting app with the debug function"); - #[cfg(debug_assertions)] - app.at("/mf2-json").get(|req: Request>| async move { - info!("DEBUG FUNCTION: Reading MF2-JSON"); - let backend = &req.state().storage; - let query = req.query::()?; - match backend.read_feed_with_limit(&query.url, &query.after, query.limit, &query.user).await { - Ok(result) => match result { - Some(post) => Ok(Response::builder(200).body(post).build()), - None => Ok(Response::builder(404).build()) - }, - Err(err) => match err.kind() { - database::ErrorKind::PermissionDenied => { - if query.user.is_some() { - Ok(Response::builder(403).build()) - } else { - Ok(Response::builder(401).build()) - } - } - _ => Ok(Response::builder(500).body(serde_json::json!({"error": "database_error", "error_description": format!("{}", err)})).build()) - } - } - }); + app.at("/").with(frontend::ErrorHandlerMiddleware {}).get(frontend::mainpage); + app.at("/static/*path").with(frontend::ErrorHandlerMiddleware {}).get(frontend::handle_static); + app.at("/*path").with(frontend::ErrorHandlerMiddleware {}).get(frontend::render_post); app } -- cgit 1.4.1