//! Defines the HTTP-based UI. These endpoints generally return HTML and SVG. use std::sync::Arc; use futures::{future, Future}; use hyper::{header, service::Service, Body, Method, Request, Response, StatusCode}; use ritz::html; use crate::{ imfs::new::ImfsFetcher, serve_session::ServeSession, web::{ interface::{NotFoundError, SERVER_VERSION}, util::json, }, }; static HOME_CSS: &str = include_str!("../../assets/index.css"); pub struct UiService { #[allow(unused)] // TODO: Fill out interface service serve_session: Arc>, } impl Service for UiService { type ReqBody = Body; type ResBody = Body; type Error = hyper::Error; type Future = Box, Error = Self::Error> + Send>; fn call(&mut self, request: Request) -> Self::Future { let response = match (request.method(), request.uri().path()) { (&Method::GET, "/") => self.handle_home(), (&Method::GET, "/visualize/rbx") => self.handle_visualize_rbx(), (&Method::GET, "/visualize/imfs") => self.handle_visualize_imfs(), _ => return json(NotFoundError, StatusCode::NOT_FOUND), }; Box::new(future::ok(response)) } } impl UiService { pub fn new(serve_session: Arc>) -> Self { UiService { serve_session } } fn handle_home(&self) -> Response { let page = html! { "Rojo"

"Rojo Live Sync is up and running!"

"Version " { SERVER_VERSION }

"Rojo Documentation"
}; Response::builder() .header(header::CONTENT_TYPE, "text/html") .body(Body::from(format!("{}", page))) .unwrap() } fn handle_visualize_rbx(&self) -> Response { Response::builder() .header(header::CONTENT_TYPE, "text/plain") .body(Body::from("TODO: /visualize/rbx")) .unwrap() } fn handle_visualize_imfs(&self) -> Response { Response::builder() .header(header::CONTENT_TYPE, "text/plain") .body(Body::from("TODO: /visualize/imfs")) .unwrap() } }