use the instance url variable
This commit is contained in:
parent
d5d0c6f4d4
commit
e73afde9bc
|
@ -7,6 +7,8 @@ use std::{collections::HashMap, convert::Infallible};
|
||||||
use warp::{reply::{Reply, Html}, Filter, reject::{Rejection, Reject}};
|
use warp::{reply::{Reply, Html}, Filter, reject::{Rejection, Reject}};
|
||||||
use askama::Template;
|
use askama::Template;
|
||||||
|
|
||||||
|
use crate::env::Env;
|
||||||
|
|
||||||
use super::{state::SharedState, rejection::HttpReject};
|
use super::{state::SharedState, rejection::HttpReject};
|
||||||
|
|
||||||
#[derive(Template)]
|
#[derive(Template)]
|
||||||
|
@ -21,25 +23,30 @@ pub struct BadActionReq {}
|
||||||
#[template( path = "uploaded.html" )]
|
#[template( path = "uploaded.html" )]
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
pub struct Uploaded {
|
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") {
|
if ! query.contains_key("file") {
|
||||||
return Err(warp::reject());
|
return Err(warp::reject());
|
||||||
}
|
}
|
||||||
|
|
||||||
let rendered = Uploaded {
|
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)))?))
|
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")
|
warp::path("uploaded")
|
||||||
.and(warp::query::<HashMap<String, String>>())
|
.and(warp::query::<HashMap<String, String>>())
|
||||||
|
.and(
|
||||||
|
warp::any().map(move || state.clone())
|
||||||
|
)
|
||||||
.and_then(uploaded)
|
.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)
|
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()
|
index_f()
|
||||||
.or(uploaded_f())
|
.or(uploaded_f(state))
|
||||||
}
|
}
|
|
@ -10,11 +10,11 @@
|
||||||
<div class="card-text">
|
<div class="card-text">
|
||||||
<p>
|
<p>
|
||||||
The file is accessible via this link:
|
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>
|
||||||
|
|
||||||
<p class="js-only">
|
<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
|
Copy link
|
||||||
</button>
|
</button>
|
||||||
</p>
|
</p>
|
||||||
|
|
Loading…
Reference in New Issue