From a425bfbc672229fe064f4df8fe192f0c8bd08f49 Mon Sep 17 00:00:00 2001 From: tomoron Date: Tue, 21 Apr 2026 11:41:31 +0200 Subject: [PATCH] fix background color, start scheduled task tests --- Cargo.lock | 237 ++++++++++++++++++++++++++++++++ Cargo.toml | 1 + assets/style.css | 5 + src/components/upload/create.rs | 41 +++--- src/main.rs | 18 ++- 5 files changed, 282 insertions(+), 20 deletions(-) create mode 100644 assets/style.css diff --git a/Cargo.lock b/Cargo.lock index 9e642c6..c3d5338 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -44,6 +44,113 @@ version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3df27b8d5ddb458c5fb1bbc1ce172d4a38c614a97d550b0ac89003897fb01de4" +[[package]] +name = "async-channel" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81953c529336010edd6d8e358f886d9581267795c61b19475b71314bffa46d35" +dependencies = [ + "concurrent-queue", + "event-listener 2.5.3", + "futures-core", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96bf972d85afc50bf5ab8fe2d54d1586b4e0b46c97c50a0c9e71e2f7bcd812a" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand 2.4.0", + "futures-lite", + "pin-project-lite", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.5.0", + "async-executor", + "async-io", + "async-lock", + "blocking", + "futures-lite", + "once_cell", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-lock" +version = "3.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "290f7f2596bd5b78a9fec8088ccd89180d7f9f55b94b0576823bbbdc72ee8311" +dependencies = [ + "event-listener 5.4.1", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-std" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c8e079a4ab67ae52b7403632e4618815d6db36d2a010cfe41b02c1b1578f93b" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io", + "async-lock", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-stream" version = "0.3.6" @@ -66,6 +173,12 @@ dependencies = [ "syn 2.0.117", ] +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + [[package]] name = "async-trait" version = "0.1.89" @@ -305,6 +418,19 @@ dependencies = [ "objc2", ] +[[package]] +name = "blocking" +version = "1.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e83f8d02be6967315521be875afa792a316e28d57b5a2d401897e2a7921b7f21" +dependencies = [ + "async-channel 2.5.0", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + [[package]] name = "bumpalo" version = "3.20.2" @@ -501,6 +627,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "const-serialize" version = "0.7.2" @@ -1795,6 +1930,33 @@ dependencies = [ "serde", ] +[[package]] +name = "event-listener" +version = "2.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0" + +[[package]] +name = "event-listener" +version = "5.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13b66accf52311f30a0db42147dadea9850cb48cd070028831ae5f5d4b856ab" +dependencies = [ + "concurrent-queue", + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener 5.4.1", + "pin-project-lite", +] + [[package]] name = "fastrand" version = "1.9.0" @@ -1978,6 +2140,19 @@ version = "0.3.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cecba35d7ad927e23624b22ad55235f2239cfa44fd10428eecbeba6d6a717718" +[[package]] +name = "futures-lite" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" +dependencies = [ + "fastrand 2.4.0", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + [[package]] name = "futures-macro" version = "0.3.32" @@ -2490,6 +2665,12 @@ version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" +[[package]] +name = "hermit-abi" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" + [[package]] name = "html5ever" version = "0.29.1" @@ -2557,6 +2738,7 @@ checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" name = "httpserver" version = "0.1.0" dependencies = [ + "async-std", "axum-core", "bigdecimal", "chrono", @@ -2983,6 +3165,15 @@ dependencies = [ "selectors", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lazy-js-bundle" version = "0.6.2" @@ -3123,6 +3314,9 @@ name = "log" version = "0.4.29" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5e5032e24019045c762d3c0f28f5b6b8bbf38563a65908389bf7978758920897" +dependencies = [ + "value-bag", +] [[package]] name = "longest-increasing-subsequence" @@ -3689,6 +3883,12 @@ dependencies = [ "system-deps", ] +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + [[package]] name = "parking_lot" version = "0.12.5" @@ -3864,6 +4064,23 @@ version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" +[[package]] +name = "pin-utils" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" + +[[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand 2.4.0", + "futures-io", +] + [[package]] name = "pkg-config" version = "0.3.32" @@ -3883,6 +4100,20 @@ dependencies = [ "miniz_oxide", ] +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "windows-sys 0.61.2", +] + [[package]] name = "pollster" version = "0.4.0" @@ -5697,6 +5928,12 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "value-bag" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ba6f5989077681266825251a52748b8c1d8a4ad098cc37e440103d0ea717fc0" + [[package]] name = "vcpkg" version = "0.2.15" diff --git a/Cargo.toml b/Cargo.toml index 4728fd6..e4cbb97 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,7 @@ repository = "https://git.tmoron.fr/tom/httpserver" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +async-std = "1.13.2" axum-core = { version = "0.5.6", optional = true } bigdecimal = "0.4.10" chrono = { version = "0.4.44", features = ["serde"] } diff --git a/assets/style.css b/assets/style.css new file mode 100644 index 0000000..7450b9c --- /dev/null +++ b/assets/style.css @@ -0,0 +1,5 @@ +html, body { + height: 100%; + margin: 0; + background: #18181b; +} diff --git a/src/components/upload/create.rs b/src/components/upload/create.rs index fa1be72..cc211fc 100644 --- a/src/components/upload/create.rs +++ b/src/components/upload/create.rs @@ -168,27 +168,30 @@ pub fn UploadFile() -> Element { } } } - input { id: "file", r#type : "file" ,multiple: false, class : "hidden", oninput: move |e| async move { - let file = &e.files()[0]; - selected.with_mut(|files| {files.push((file.name(), byte_to_human_size(file.size()), None)); } ); - let idx = selected().len() - 1; + input { id: "file", r#type : "file" ,multiple: true, class : "hidden", oninput: move |e| async move { + //let file = &e.files()[0]; + for file in e.files() + { + selected.with_mut(|files| {files.push((file.name(), byte_to_human_size(file.size()), None)); } ); + let idx = selected().len() - 1; - if file.size() > config.upload_max_size as u64 { - //messy but firefox can't handle when server returns early - selected.with_mut(|files| { files[idx].2 = Some(HttpError::payload_too_large("This file is too large")) }); - return ; + if file.size() > config.upload_max_size as u64 { + //messy but firefox can't handle when server returns early + selected.with_mut(|files| { files[idx].2 = Some(HttpError::payload_too_large("This file is too large")) }); + return ; + } + + let res = match upload_file(file.clone().into()).await { + Ok(file_id) => { + let location = web_sys::window().unwrap().location(); + let host = location.host().expect("unknown host"); + let protocol = location.protocol().expect("unknown protocol"); + Ok(protocol + "//" + &host + "/upload/" + &file_id) + }, + Err(err) => { Err(err) } + }; + selected.with_mut(|files| { files[idx].2 = Some(res) }); } - - let res = match upload_file(file.clone().into()).await { - Ok(file_id) => { - let location = web_sys::window().unwrap().location(); - let host = location.host().expect("unknown host"); - let protocol = location.protocol().expect("unknown protocol"); - Ok(protocol + "//" + &host + "/upload/" + &file_id) - }, - Err(err) => { Err(err) } - }; - selected.with_mut(|files| { files[idx].2 = Some(res) }); }} } } diff --git a/src/main.rs b/src/main.rs index 5a75fca..b164802 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,6 +6,9 @@ use tracing::Level; pub mod config; +use async_std::task; +use std::time::Duration; + use crate::components::toast::ToastProvider; use crate::views::{ @@ -39,16 +42,28 @@ enum Route { const FAVICON: Asset = asset!("/assets/favicon.ico"); +const STYLE_CSS: Asset = asset!("/assets/style.css"); const TAILWIND_CSS: Asset = asset!("/assets/tailwind.css"); + fn main() { #[cfg(feature = "server")] let _ = ServerConfig::load(); + #[cfg(feature = "server")] + task::spawn(scheduled_tasks()); + dioxus::logger::init(Level::INFO).expect("failed to init logger"); dioxus::launch(App); } +async fn scheduled_tasks() { + loop { + task::sleep(Duration::from_secs(1)).await; +// tracing::info!("patate douce"); + } +} + #[component] fn ErrorLayout() -> Element { rsx! { @@ -69,9 +84,10 @@ fn ErrorLayout() -> Element { fn App() -> Element { rsx! { document::Link { rel: "icon", href: FAVICON } + document::Link { rel: "stylesheet", href: STYLE_CSS } document::Link { rel: "stylesheet", href: TAILWIND_CSS } div { - class: "h-screen w-screen bg-zinc-900 text-white", + class: "h-full w-full text-white", ToastProvider { Router:: {} }