From ce8737b0f571b44b3aaa250ef7cf26e4b328c9d1 Mon Sep 17 00:00:00 2001 From: blek Date: Sun, 1 Oct 2023 21:42:48 +1000 Subject: [PATCH] load instance url from Env struct --- filed/src/web/pages.rs | 28 ++++++++++++++++++---------- filed/templates/seotags.html | 5 +++-- filed/templates/uploaded.html | 4 ++-- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/filed/src/web/pages.rs b/filed/src/web/pages.rs index 091b9f6..6a454fb 100644 --- a/filed/src/web/pages.rs +++ b/filed/src/web/pages.rs @@ -13,18 +13,22 @@ use super::{state::SharedState, rejection::HttpReject}; #[derive(Template)] #[template( path = "index.html" )] -pub struct Index {} +pub struct Index { + env: Env +} #[derive(Template)] #[template( path = "bad_action_req.html" )] -pub struct BadActionReq {} +pub struct BadActionReq { + env: Env +} #[derive(Template)] #[template( path = "uploaded.html" )] #[allow(dead_code)] pub struct Uploaded { file: String, - instance_url: String + env: Env } @@ -36,7 +40,7 @@ pub async fn uploaded(query: HashMap, state: SharedState) -> Res let rendered = Uploaded { file: query.get("file").unwrap().clone(), - instance_url: state.env.instanceurl.clone() + env: state.env.clone() }; Ok(warp::reply::html(rendered.render().map_err(|err| warp::reject::custom(HttpReject::AskamaError(err)))?)) } @@ -50,16 +54,20 @@ pub fn uploaded_f(state: SharedState) -> impl Filter Result, Rejection> { - let rendered = Index {}; +pub async fn index(state: SharedState) -> Result, Rejection> { + let rendered = Index { + env: state.env.clone() + }; 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 index_f(state: SharedState) -> impl Filter + Clone { + warp::path::end() + .map(move || state.clone()) + .and_then(index) } pub fn get_routes(state: SharedState) -> impl Filter + Clone { - index_f() - .or(uploaded_f(state)) + index_f(state.clone()) + .or(uploaded_f(state.clone())) } \ No newline at end of file diff --git a/filed/templates/seotags.html b/filed/templates/seotags.html index 74b37b2..981a863 100644 --- a/filed/templates/seotags.html +++ b/filed/templates/seotags.html @@ -11,8 +11,9 @@ - - + + + diff --git a/filed/templates/uploaded.html b/filed/templates/uploaded.html index 41e9265..51b7caa 100644 --- a/filed/templates/uploaded.html +++ b/filed/templates/uploaded.html @@ -10,11 +10,11 @@

The file is accessible via this link: - {{ instance_url }}/file/{{ file }} + {{ env.instanceurl }}/file/{{ file }}

-