use the instance url variable

This commit is contained in:
blek 2023-10-01 21:14:18 +10:00
parent d5d0c6f4d4
commit e73afde9bc
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 15 additions and 8 deletions

View File

@ -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<String, String>) -> Result<Html<String>, Rejection> {
pub async fn uploaded(query: HashMap<String, String>, state: SharedState) -> Result<Html<String>, 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<Extract = impl Reply, Error = warp::Rejection> + Clone {
pub fn uploaded_f(state: SharedState) -> impl Filter<Extract = impl Reply, Error = warp::Rejection> + Clone {
warp::path("uploaded")
.and(warp::query::<HashMap<String, String>>())
.and(
warp::any().map(move || state.clone())
)
.and_then(uploaded)
}
@ -52,7 +59,7 @@ pub fn index_f() -> impl Filter<Extract = impl Reply, Error = warp::Rejection> +
warp::path::end().and_then(index)
}
pub fn get_routes(_state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
pub fn get_routes(state: SharedState) -> impl Filter<Extract = impl Reply, Error = Rejection> + Clone {
index_f()
.or(uploaded_f())
.or(uploaded_f(state))
}

View File

@ -10,11 +10,11 @@
<div class="card-text">
<p>
The file is accessible via this link:
<a href='/file/{{ file }}'>file.blek.codes/file/{{ file }}</a>
<a href='{{ instance_url }}/file/{{ file }}'>{{ instance_url }}/file/{{ file }}</a>
</p>
<p class="js-only">
<button class="btn btn-fill" style="cursor:pointer" id="copylink" data-clipboard-text="https://file.blek.codes/file/{{ file }}">
<button class="btn btn-fill" style="cursor:pointer" id="copylink" data-clipboard-text="{{ instance_url }}/file/{{ file }}">
Copy link
</button>
</p>