From e73afde9bc5e7f8e50f0efcd95316ebb309bad89 Mon Sep 17 00:00:00 2001 From: blek Date: Sun, 1 Oct 2023 21:14:18 +1000 Subject: [PATCH] use the instance url variable --- filed/src/web/pages.rs | 19 +++++++++++++------ filed/templates/uploaded.html | 4 ++-- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/filed/src/web/pages.rs b/filed/src/web/pages.rs index 02ba0a2..091b9f6 100644 --- a/filed/src/web/pages.rs +++ b/filed/src/web/pages.rs @@ -7,6 +7,8 @@ use std::{collections::HashMap, convert::Infallible}; use warp::{reply::{Reply, Html}, Filter, reject::{Rejection, Reject}}; use askama::Template; +use crate::env::Env; + use super::{state::SharedState, rejection::HttpReject}; #[derive(Template)] @@ -21,25 +23,30 @@ pub struct BadActionReq {} #[template( path = "uploaded.html" )] #[allow(dead_code)] pub struct Uploaded { - file: String + file: String, + instance_url: String } -pub async fn uploaded(query: HashMap) -> Result, Rejection> { +pub async fn uploaded(query: HashMap, state: SharedState) -> Result, Rejection> { if ! query.contains_key("file") { return Err(warp::reject()); } let rendered = Uploaded { - file: query.get("file").unwrap().clone() + file: query.get("file").unwrap().clone(), + instance_url: state.env.instanceurl.clone() }; Ok(warp::reply::html(rendered.render().map_err(|err| warp::reject::custom(HttpReject::AskamaError(err)))?)) } -pub fn uploaded_f() -> impl Filter + Clone { +pub fn uploaded_f(state: SharedState) -> impl Filter + Clone { warp::path("uploaded") .and(warp::query::>()) + .and( + warp::any().map(move || state.clone()) + ) .and_then(uploaded) } @@ -52,7 +59,7 @@ pub fn index_f() -> impl Filter + warp::path::end().and_then(index) } -pub fn get_routes(_state: SharedState) -> impl Filter + Clone { +pub fn get_routes(state: SharedState) -> impl Filter + Clone { index_f() - .or(uploaded_f()) + .or(uploaded_f(state)) } \ No newline at end of file diff --git a/filed/templates/uploaded.html b/filed/templates/uploaded.html index 6816e2a..41e9265 100644 --- a/filed/templates/uploaded.html +++ b/filed/templates/uploaded.html @@ -10,11 +10,11 @@

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

-