copy text and other small changes

This commit is contained in:
2026-04-07 13:39:14 +02:00
parent 3f555079aa
commit 9b65c5f62b
9 changed files with 277 additions and 357 deletions

520
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -15,7 +15,7 @@ random-string = "1.1.0"
reqwest = { version = "0.13.2", features = ["stream"] }
tracing = "0.1.44"
wasm-bindgen = "0.2.114"
web-sys = { version = "0.3.91", features = ["XmlHttpRequest", "XmlHttpRequestUpload", "ProgressEvent" ] }
web-sys = { version = "0.3.91", features = [ "Navigator", "Clipboard" ] }
[features]
default = ["web"]

View File

@ -4,13 +4,6 @@ pkgs.mkShell {
rustup
];
nativeBuildInputs = with pkgs;[
openssl
glib
gdk-pixbuf
pango
atk
xdo
lld
];
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";

View File

@ -1,6 +1,6 @@
use dioxus::prelude::*;
use views::{Blog, Home, Navbar, Upload};
use views::{Upload};
use tracing::Level;
mod components;
@ -11,15 +11,9 @@ mod views;
enum Route {
#[route("/upload")]
Upload {},
#[layout(Navbar)]
#[route("/")]
Home {},
#[route("/blog/:id")]
Blog { id: i32 },
}
const FAVICON: Asset = asset!("/assets/favicon.ico");
//const MAIN_CSS: Asset = asset!("/assets/styling/main.css");
const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css");
fn main() {

View File

@ -1,30 +0,0 @@
use crate::Route;
use dioxus::prelude::*;
use crate::components::{Hero};
//const BLOG_CSS: Asset = asset!("/assets/styling/blog.css");
#[component]
pub fn Blog(id: i32) -> Element {
rsx! {
// document::Link { rel: "stylesheet", href: BLOG_CSS }
div {
id: "blog",
h1 { "This is blog #{id}!" }
p { "In blog #{id}, we show how the Dioxus router works and how URL parameters can be passed as props to our route components." }
Link {
to: Route::Blog { id: id - 1 },
"Previous"
}
span { " <---> " }
Link {
to: Route::Blog { id: id + 1 },
"Next"
}
}
Hero{}
}
}

View File

@ -1,11 +0,0 @@
use dioxus::prelude::*;
use crate::components::{Hero, Echo};
/// The Home page component that will be rendered when the current route is `[Route::Home]`
#[component]
pub fn Home() -> Element {
rsx! {
Hero {}
Echo {}
}
}

View File

@ -1,11 +1,2 @@
mod home;
pub use home::Home;
mod blog;
pub use blog::Blog;
mod navbar;
pub use navbar::Navbar;
mod upload;
pub use upload::Upload;

View File

@ -1,25 +0,0 @@
use crate::Route;
use dioxus::prelude::*;
//const NAVBAR_CSS: Asset = asset!("/assets/styling/navbar.css");
#[component]
pub fn Navbar() -> Element {
rsx! {
// document::Link { rel: "stylesheet", href: NAVBAR_CSS }
div {
id: "navbar",
Link {
to: Route::Home {},
"Home"
}
Link {
to: Route::Blog { id: 1 },
"Blog"
}
}
Outlet::<Route> {}
}
}

View File

@ -45,8 +45,10 @@ async fn upload_file(mut upload: FileStream) -> Result<String, HttpError> {
}
};
if upload.size().unwrap() > UPLOAD_SIZE_LIMIT {
return HttpError::payload_too_large("this file is too large");
if let Some(size) = upload.size() {
if size > UPLOAD_SIZE_LIMIT {
return HttpError::payload_too_large("this file is too large");
}
}
@ -60,7 +62,7 @@ async fn upload_file(mut upload: FileStream) -> Result<String, HttpError> {
Ok(bytes) => {
total_len += bytes.len() as u64;
if total_len > UPLOAD_SIZE_LIMIT {
error = Some("Uploaded file to large");
error = Some("Uploaded file too large");
break;
}
@ -97,7 +99,11 @@ pub fn build_table(files: Vec<(String, String, Option<Result<String, HttpError>>
td { class: "px-2",
match &file.2 {
Some(res) => { match res {
Ok(file_id) => { rsx! { input { type:"button" , "/upload/dl/{file_id}"} } },
Ok(file_url) => {let url = file_url.clone(); rsx! { input {
type:"button",
onclick: move |_| { web_sys::window().unwrap().navigator().clipboard().write_text(&url); },
value: "{file_url}"
} } },
Err(e) => {
let msg = e.message.clone().unwrap();
rsx! { p { "Upload failed, reason : {msg}" } }
@ -144,7 +150,13 @@ pub fn Upload() -> Element {
return ;
}
let res = upload_file(file.clone().into()).await;
let res = match upload_file(file.clone().into()).await {
Ok(file_id) => {
let host = web_sys::window().unwrap().location().host().expect("unknown_host");
Ok(host + "/upload/" + &file_id)
},
Err(err) => { Err(err) }
};
selected.with_mut(|files| { files[idx].2 = Some(res) });
}}
}