From 3f1316b3ddf7fa40e62f059ba7b658afb1612b57 Mon Sep 17 00:00:00 2001 From: Savanni D'Gerinel Date: Fri, 6 Oct 2023 19:04:15 -0400 Subject: [PATCH] Serve the CSS file --- file-service/src/handlers.rs | 9 +++++++++ file-service/src/main.rs | 7 +++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/file-service/src/handlers.rs b/file-service/src/handlers.rs index 699451a..96478df 100644 --- a/file-service/src/handlers.rs +++ b/file-service/src/handlers.rs @@ -9,6 +9,8 @@ use warp::{filters::multipart::FormData, http::Response, multipart::Part}; use crate::{pages, App, AuthToken, FileId, FileInfo, ReadFileError, SessionToken}; +const CSS: &str = include_str!("../templates/style.css"); + pub async fn handle_index( app: App, token: Option, @@ -22,6 +24,13 @@ pub async fn handle_index( } } +pub async fn handle_css() -> Result, Error> { + Response::builder() + .header("content-type", "text/css") + .status(StatusCode::OK) + .body(CSS.to_owned()) +} + pub fn render_auth_page(message: Option) -> Result, Error> { Response::builder() .status(StatusCode::OK) diff --git a/file-service/src/main.rs b/file-service/src/main.rs index c70f7ff..88b69cc 100644 --- a/file-service/src/main.rs +++ b/file-service/src/main.rs @@ -1,7 +1,7 @@ extern crate log; use cookie::Cookie; -use handlers::{file, handle_auth, handle_upload, thumbnail}; +use handlers::{file, handle_auth, handle_css, handle_upload, thumbnail}; use std::{ collections::{HashMap, HashSet}, convert::Infallible, @@ -119,6 +119,8 @@ pub async fn main() { .and(maybe_with_session()) .then(handle_index); + let styles = warp::path!("css").and(warp::get()).then(handle_css); + let auth = warp::path!("auth") .and(warp::post()) .and(with_app(app.clone())) @@ -145,7 +147,8 @@ pub async fn main() { .then(move |id, old_etags, app: App| file(app, id, old_etags)); let server = warp::serve( - root.or(auth) + root.or(styles) + .or(auth) .or(upload_via_form) .or(thumbnail) .or(file)