file uploaded page

This commit is contained in:
blek 2023-10-10 21:56:28 +10:00
parent bddd63e134
commit a201fd579d
Signed by: blek
GPG Key ID: 14546221E3595D0C
9 changed files with 117 additions and 4 deletions

View File

@ -1,3 +1,7 @@
:80 { :80 {
reverse_proxy http://filed reverse_proxy http://filed
handle /qr/* {
uri * strip_prefix /qr
reverse_proxy http://qr
}
} }

View File

@ -25,6 +25,10 @@ services:
command: [ 'redis-server', '--requirepass', '$REDIS_PASS' ] command: [ 'redis-server', '--requirepass', '$REDIS_PASS' ]
ports: ports:
- 6379:6379 - 6379:6379
qr:
image: blekii/miniqr
networks:
bfile:
networks: networks:
bfile: bfile:

9
filed/Cargo.lock generated
View File

@ -288,6 +288,7 @@ dependencies = [
"sha2", "sha2",
"static_dir", "static_dir",
"tokio", "tokio",
"urlencoding 2.1.3",
"warp", "warp",
] ]
@ -1067,7 +1068,7 @@ dependencies = [
"log", "log",
"mime_guess", "mime_guess",
"once_cell", "once_cell",
"urlencoding", "urlencoding 1.3.3",
"warp", "warp",
] ]
@ -1366,6 +1367,12 @@ version = "1.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a1f0175e03a0973cf4afd476bef05c26e228520400eb1fd473ad417b1c00ffb" checksum = "5a1f0175e03a0973cf4afd476bef05c26e228520400eb1fd473ad417b1c00ffb"
[[package]]
name = "urlencoding"
version = "2.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da"
[[package]] [[package]]
name = "utf-8" name = "utf-8"
version = "0.7.6" version = "0.7.6"

View File

@ -22,6 +22,7 @@ serde_json = "1.0.107"
sha2 = "0.10.8" sha2 = "0.10.8"
static_dir = "0.2.0" static_dir = "0.2.0"
tokio = { version = "1.32.0", features = ["rt", "macros", "rt-multi-thread"] } tokio = { version = "1.32.0", features = ["rt", "macros", "rt-multi-thread"] }
urlencoding = "2.1.3"
warp = "0.3.6" warp = "0.3.6"
[profile.release] [profile.release]

View File

@ -13,7 +13,7 @@ use serde::Serialize;
use crate::files::{File, lookup::LookupKind}; use crate::files::{File, lookup::LookupKind};
use super::{state::SharedState, pages::BadActionReq, rejection::HttpReject}; use super::{state::SharedState, pages::{BadActionReq, UploadSuccessPage}, rejection::HttpReject};
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
struct FormElement { struct FormElement {
@ -99,7 +99,13 @@ pub async fn upload(form: FormData, state: SharedState) -> Result<Box<dyn Reply>
} }
}).map_err(|err| warp::reject::custom(HttpReject::StringError(err.to_string())))?; }).map_err(|err| warp::reject::custom(HttpReject::StringError(err.to_string())))?;
Ok(Box::new(warp::reply::json(&params))) let uploaded = UploadSuccessPage {
env: state.env.clone(),
link: "uwu".into()
};
Ok(Box::new(warp::reply::html(uploaded.render().unwrap())))
} }
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 {

View File

@ -38,6 +38,14 @@ pub struct PasswordedFilesHelpPage {
pub env: Env pub env: Env
} }
#[derive(Template)]
#[template( path = "upload_success.html" )]
#[allow(dead_code)]
pub struct UploadSuccessPage {
pub env: Env,
pub link: String
}
pub async fn uploaded(query: HashMap<String, String>, state: SharedState) -> Result<Html<String>, Rejection> { pub async fn uploaded(query: HashMap<String, String>, state: SharedState) -> Result<Html<String>, Rejection> {

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,5 @@
@media (max-width:667px) {
.mobile-hide {
display: none
}
}

View File

@ -0,0 +1,71 @@
{% extends "base.html" %}
{% block head %}
<link rel="stylesheet" href="/mobile-hide.css"></link>
<style>
.qr-code {
display: block;
min-height: min(160px, 35vw);
width: min(160px, 35vw);
object-fit: contain;
image-rendering: pixelated;
padding: min(40px, 8vw);
background: white;
margin: min(40px, 8vw) auto;
border-radius: 12px;
}
.btn-fill {
width: calc(100% - var(--margin-x));
}
</style>
{% endblock %}
{% block body %}
<div style="max-width:75vw;width:fit-content;margin:0 auto;text-align:center">
<h1 style="text-align:center;margin-bottom:0">File uploaded successfully!</h1>
<p style="margin-top:4px;font-size:90%">
It is available via the following link:
<a href='{{ link }}'>
{{ link }}
</a>
</p>
<div style="width:100%">
<img src="{{ env.instanceurl }}/qr/{{ urlencoding::encode(link) }}" class="qr-code">
</div>
<a href="/" role="button" class="btn btn-fill" style="display:block" >
Upload another file
</a>
<br/>
<div class="js-only btn btn-fill" style="cursor:pointer" id="btn-upload-done" data-clipboard-text="{{ env.instanceurl }}/qr/{{ urlencoding::encode(link) }}">
Copy link
</div>
</div>
{% endblock %}
{% block scripts %}
<script>document.getElementById('btn-upload-done').style.display = 'block'</script>
<script src="https://unpkg.com/clipboard@2/dist/clipboard.min.js"></script>
<script>
new ClipboardJS('#btn-upload-done');
(()=>{
let e = document.getElementById('btn-upload-done');
let animating = false;
e.onclick = () => {
if (animating) return
let old = e.innerText;
e.innerText = 'Copied!'
animating = true;
setTimeout(() => {
e.innerText = old;
animating = false
}, 1500);
}
})()
</script>
{% endblock %}