From 90c7f3da72131f193e6a36d14409d0f11185d8e2 Mon Sep 17 00:00:00 2001 From: blek Date: Sun, 1 Oct 2023 21:02:19 +1000 Subject: [PATCH] uploaded page --- filed/src/web/pages.rs | 44 +++++++++++++++++++++++++++++------ filed/templates/uploaded.html | 36 ++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 filed/templates/uploaded.html diff --git a/filed/src/web/pages.rs b/filed/src/web/pages.rs index d39fa36..02ba0a2 100644 --- a/filed/src/web/pages.rs +++ b/filed/src/web/pages.rs @@ -2,10 +2,12 @@ pages.rs - All the HTML pages */ -use warp::{reply::{Reply, Html}, Filter, reject::Rejection}; +use std::{collections::HashMap, convert::Infallible}; + +use warp::{reply::{Reply, Html}, Filter, reject::{Rejection, Reject}}; use askama::Template; -use super::state::SharedState; +use super::{state::SharedState, rejection::HttpReject}; #[derive(Template)] #[template( path = "index.html" )] @@ -15,14 +17,42 @@ pub struct Index {} #[template( path = "bad_action_req.html" )] pub struct BadActionReq {} +#[derive(Template)] +#[template( path = "uploaded.html" )] +#[allow(dead_code)] +pub struct Uploaded { + file: String +} -pub fn index() -> Html { + +pub async fn uploaded(query: HashMap) -> Result, Rejection> { + + if ! query.contains_key("file") { + return Err(warp::reject()); + } + + let rendered = Uploaded { + file: query.get("file").unwrap().clone() + }; + Ok(warp::reply::html(rendered.render().map_err(|err| warp::reject::custom(HttpReject::AskamaError(err)))?)) +} + +pub fn uploaded_f() -> impl Filter + Clone { + warp::path("uploaded") + .and(warp::query::>()) + .and_then(uploaded) +} + +pub async fn index() -> Result, Rejection> { let rendered = Index {}; - warp::reply::html(rendered.render().unwrap()) + Ok(warp::reply::html(rendered.render().map_err(|err| warp::reject::custom(HttpReject::AskamaError(err)))?)) +} + +pub fn index_f() -> impl Filter + Clone { + warp::path::end().and_then(index) } pub fn get_routes(_state: SharedState) -> impl Filter + Clone { - let index_r = warp::path::end().map(index); - - warp::any().and(index_r) + index_f() + .or(uploaded_f()) } \ No newline at end of file diff --git a/filed/templates/uploaded.html b/filed/templates/uploaded.html new file mode 100644 index 0000000..6816e2a --- /dev/null +++ b/filed/templates/uploaded.html @@ -0,0 +1,36 @@ +{% extends "base.html" %} + +{% block body %} + +
+
+
+ Successfully uploaded a file +
+
+

+ The file is accessible via this link: + file.blek.codes/file/{{ file }} +

+ +

+ +

+
+
+
+ +{% endblock %} + +{% block scripts %} + + + + +{% endblock %} \ No newline at end of file