From a201fd579decc2203fc576922205f5070d2151cb Mon Sep 17 00:00:00 2001 From: blek Date: Tue, 10 Oct 2023 21:56:28 +1000 Subject: [PATCH] file uploaded page --- conf/caddy/Caddyfile | 4 ++ docker-compose.dev.yml | 6 ++- filed/Cargo.lock | 9 +++- filed/Cargo.toml | 1 + filed/src/web/forms.rs | 10 +++- filed/src/web/pages.rs | 8 ++++ filed/static/lib/clipboard.js | 7 +++ filed/static/mobile-hide.css | 5 ++ filed/templates/upload_success.html | 71 +++++++++++++++++++++++++++++ 9 files changed, 117 insertions(+), 4 deletions(-) create mode 100644 filed/static/lib/clipboard.js create mode 100644 filed/static/mobile-hide.css create mode 100644 filed/templates/upload_success.html diff --git a/conf/caddy/Caddyfile b/conf/caddy/Caddyfile index 5c0d6ce..e52811c 100644 --- a/conf/caddy/Caddyfile +++ b/conf/caddy/Caddyfile @@ -1,3 +1,7 @@ :80 { reverse_proxy http://filed + handle /qr/* { + uri * strip_prefix /qr + reverse_proxy http://qr + } } \ No newline at end of file diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml index 8dd1cd4..093e0d6 100644 --- a/docker-compose.dev.yml +++ b/docker-compose.dev.yml @@ -25,6 +25,10 @@ services: command: [ 'redis-server', '--requirepass', '$REDIS_PASS' ] ports: - 6379:6379 - + qr: + image: blekii/miniqr + networks: + bfile: + networks: bfile: \ No newline at end of file diff --git a/filed/Cargo.lock b/filed/Cargo.lock index a46b163..deec126 100644 --- a/filed/Cargo.lock +++ b/filed/Cargo.lock @@ -288,6 +288,7 @@ dependencies = [ "sha2", "static_dir", "tokio", + "urlencoding 2.1.3", "warp", ] @@ -1067,7 +1068,7 @@ dependencies = [ "log", "mime_guess", "once_cell", - "urlencoding", + "urlencoding 1.3.3", "warp", ] @@ -1366,6 +1367,12 @@ version = "1.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a1f0175e03a0973cf4afd476bef05c26e228520400eb1fd473ad417b1c00ffb" +[[package]] +name = "urlencoding" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "daf8dba3b7eb870caf1ddeed7bc9d2a049f3cfdfae7cb521b087cc33ae4c49da" + [[package]] name = "utf-8" version = "0.7.6" diff --git a/filed/Cargo.toml b/filed/Cargo.toml index 5c8e947..9a8cb04 100644 --- a/filed/Cargo.toml +++ b/filed/Cargo.toml @@ -22,6 +22,7 @@ serde_json = "1.0.107" sha2 = "0.10.8" static_dir = "0.2.0" tokio = { version = "1.32.0", features = ["rt", "macros", "rt-multi-thread"] } +urlencoding = "2.1.3" warp = "0.3.6" [profile.release] diff --git a/filed/src/web/forms.rs b/filed/src/web/forms.rs index 6ebe2b5..d6eddd2 100644 --- a/filed/src/web/forms.rs +++ b/filed/src/web/forms.rs @@ -13,7 +13,7 @@ use serde::Serialize; 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)] struct FormElement { @@ -99,7 +99,13 @@ pub async fn upload(form: FormData, state: SharedState) -> Result } }).map_err(|err| warp::reject::custom(HttpReject::StringError(err.to_string())))?; - Ok(Box::new(warp::reply::json(¶ms))) + 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 + Clone { diff --git a/filed/src/web/pages.rs b/filed/src/web/pages.rs index 19339ad..a79fa43 100644 --- a/filed/src/web/pages.rs +++ b/filed/src/web/pages.rs @@ -38,6 +38,14 @@ pub struct PasswordedFilesHelpPage { 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, state: SharedState) -> Result, Rejection> { diff --git a/filed/static/lib/clipboard.js b/filed/static/lib/clipboard.js new file mode 100644 index 0000000..1103f81 --- /dev/null +++ b/filed/static/lib/clipboard.js @@ -0,0 +1,7 @@ +/*! + * clipboard.js v2.0.11 + * https://clipboardjs.com/ + * + * Licensed MIT © Zeno Rocha + */ +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.ClipboardJS=e():t.ClipboardJS=e()}(this,function(){return n={686:function(t,e,n){"use strict";n.d(e,{default:function(){return b}});var e=n(279),i=n.n(e),e=n(370),u=n.n(e),e=n(817),r=n.n(e);function c(t){try{return document.execCommand(t)}catch(t){return}}var a=function(t){t=r()(t);return c("cut"),t};function o(t,e){var n,o,t=(n=t,o="rtl"===document.documentElement.getAttribute("dir"),(t=document.createElement("textarea")).style.fontSize="12pt",t.style.border="0",t.style.padding="0",t.style.margin="0",t.style.position="absolute",t.style[o?"right":"left"]="-9999px",o=window.pageYOffset||document.documentElement.scrollTop,t.style.top="".concat(o,"px"),t.setAttribute("readonly",""),t.value=n,t);return e.container.appendChild(t),e=r()(t),c("copy"),t.remove(),e}var f=function(t){var e=1 + + +{% endblock %} + +{% block body %} + +
+

File uploaded successfully!

+

+ It is available via the following link: + + {{ link }} + +

+
+ +
+ + Upload another file + +
+
+ Copy link +
+
+ +{% endblock %} + +{% block scripts %} + + + + + +{% endblock %} \ No newline at end of file