uploaded page

This commit is contained in:
blek 2023-10-01 21:02:19 +10:00
parent 6bd7171173
commit 90c7f3da72
Signed by: blek
GPG Key ID: 14546221E3595D0C
2 changed files with 73 additions and 7 deletions

View File

@ -2,10 +2,12 @@
pages.rs - All the HTML pages 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 askama::Template;
use super::state::SharedState; use super::{state::SharedState, rejection::HttpReject};
#[derive(Template)] #[derive(Template)]
#[template( path = "index.html" )] #[template( path = "index.html" )]
@ -15,14 +17,42 @@ pub struct Index {}
#[template( path = "bad_action_req.html" )] #[template( path = "bad_action_req.html" )]
pub struct BadActionReq {} pub struct BadActionReq {}
#[derive(Template)]
#[template( path = "uploaded.html" )]
#[allow(dead_code)]
pub struct Uploaded {
file: String
}
pub fn index() -> Html<String> {
pub async fn uploaded(query: HashMap<String, String>) -> Result<Html<String>, 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<Extract = impl Reply, Error = warp::Rejection> + Clone {
warp::path("uploaded")
.and(warp::query::<HashMap<String, String>>())
.and_then(uploaded)
}
pub async fn index() -> Result<Html<String>, Rejection> {
let rendered = Index {}; 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<Extract = impl Reply, Error = warp::Rejection> + Clone {
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 {
let index_r = warp::path::end().map(index); index_f()
.or(uploaded_f())
warp::any().and(index_r)
} }

View File

@ -0,0 +1,36 @@
{% extends "base.html" %}
{% block body %}
<div style="margin:0 12px">
<div class="card" style="width: fit-content; margin:0 auto">
<div class="card-title">
Successfully uploaded a file
</div>
<div class="card-text">
<p>
The file is accessible via this link:
<a href='/file/{{ file }}'>file.blek.codes/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 }}">
Copy link
</button>
</p>
</div>
</div>
</div>
{% endblock %}
{% block scripts %}
<script src="https://unpkg.com/clipboard@2/dist/clipboard.min.js"></script>
<script>
(() => {
new ClipboardJS('#copylink');
})()
</script>
{% endblock %}