From f6eae91c7d7253ccfd950403a8f3b78f84837375 Mon Sep 17 00:00:00 2001 From: Kerollmops Date: Sat, 11 Jul 2020 14:17:37 +0200 Subject: [PATCH] Pretty print the new dashboard numbers --- Cargo.lock | 86 ++++++++++++++++++++++++++++++++ Cargo.toml | 2 + public/filesize.min.js | 6 +++ public/script.js | 10 ++++ src/bin/serve.rs | 37 +++++++++++++- {public => templates}/index.html | 11 ++-- 6 files changed, 146 insertions(+), 6 deletions(-) create mode 100644 public/filesize.min.js rename {public => templates}/index.html (86%) diff --git a/Cargo.lock b/Cargo.lock index b6f0e8c27..02a09ca2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,6 +18,65 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b585a98a234c46fc563103e9278c9391fde1f4e6850334da895d27edb9580f62" +[[package]] +name = "askama" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afb6c2f00d120a43d67345bbd3e9e21d1ee090c1fc7db7787c05bd969b83bccf" +dependencies = [ + "askama_derive", + "askama_escape", + "askama_shared", + "mime 0.3.16", + "mime_guess 2.0.3", +] + +[[package]] +name = "askama_derive" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d97b96db4caba8842ec48a537cab1e6d7e809d7a408c97ae99f129e1c982750" +dependencies = [ + "askama_shared", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "askama_escape" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "90c108c1a94380c89d2215d0ac54ce09796823cca0fd91b299cfff3b33e346fb" + +[[package]] +name = "askama_shared" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3342887c2f85a336bc8bc4fc79603434539cdae37565e20ccf54599dea8e42ee" +dependencies = [ + "askama_escape", + "humansize", + "nom", + "num-traits", + "percent-encoding", + "proc-macro2", + "quote", + "serde", + "syn", + "toml", +] + +[[package]] +name = "askama_warp" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c96f410ab17fa08f70b5fda07ce1112418642c914864961630808979343ea226" +dependencies = [ + "askama", + "warp", +] + [[package]] name = "atty" version = "0.2.14" @@ -654,6 +713,12 @@ version = "1.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" +[[package]] +name = "humansize" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6cab2627acfc432780848602f3f558f7e9dd427352224b0d9324025796d2a5e" + [[package]] name = "hyper" version = "0.13.6" @@ -847,6 +912,8 @@ name = "mega-mini-indexer" version = "0.1.0" dependencies = [ "anyhow", + "askama", + "askama_warp", "bitpacking", "byteorder", "cow-utils", @@ -1038,6 +1105,16 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "nom" +version = "5.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af" +dependencies = [ + "memchr", + "version_check 0.9.2", +] + [[package]] name = "num-traits" version = "0.2.12" @@ -1824,6 +1901,15 @@ dependencies = [ "tokio", ] +[[package]] +name = "toml" +version = "0.5.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffc92d160b1eef40665be3a05630d003936a3bc7da7421277846c2613e92c71a" +dependencies = [ + "serde", +] + [[package]] name = "tower-service" version = "0.3.0" diff --git a/Cargo.toml b/Cargo.toml index dea1d6086..41e1af998 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,6 +34,8 @@ indexmap = "1.4.0" itertools = "0.9.0" # http server +askama = "0.10.1" +askama_warp = "0.10.0" serde = { version = "1.0", features = ["derive"] } tokio = { version = "0.2.15", features = ["full"] } warp = "0.2.2" diff --git a/public/filesize.min.js b/public/filesize.min.js new file mode 100644 index 000000000..0d4df433f --- /dev/null +++ b/public/filesize.min.js @@ -0,0 +1,6 @@ +/* + 2020 Jason Mulligan + @version 6.1.0 +*/ +"use strict";!function(e){var x=/^(b|B)$/,M={iec:{bits:["b","Kib","Mib","Gib","Tib","Pib","Eib","Zib","Yib"],bytes:["B","KiB","MiB","GiB","TiB","PiB","EiB","ZiB","YiB"]},jedec:{bits:["b","Kb","Mb","Gb","Tb","Pb","Eb","Zb","Yb"],bytes:["B","KB","MB","GB","TB","PB","EB","ZB","YB"]}},w={iec:["","kibi","mebi","gibi","tebi","pebi","exbi","zebi","yobi"],jedec:["","kilo","mega","giga","tera","peta","exa","zetta","yotta"]};function t(e){var i,t,o,n,b,r,a,l,s,d,u,c,f,p,B,y=1 anyhow::Result<()> { let opt = Opt::from_args(); @@ -44,12 +54,29 @@ async fn main() -> anyhow::Result<()> { let index = Index::new(&env)?; + // Retrieve the database the file stem (w/o the extension) + let db_name = opt.database.file_stem().and_then(|s| s.to_str()).unwrap_or("").to_string(); + + // Retrieve the disk file size + let db_size = File::open(opt.database.join("data.mdb"))?.metadata()?.len() as usize; + + // Precompute the number of documents in the database. + let rtxn = env.read_txn().unwrap(); + let docs_count = index.documents.len(&rtxn)?; + drop(rtxn); + // We run and wait on the HTTP server // Expose an HTML page to debug the search in a browser let dash_html_route = warp::filters::method::get() .and(warp::filters::path::end()) - .map(|| warp::reply::html(include_str!("../../public/index.html"))); + .map(move || { + IndexTemplate { + db_name: db_name.clone(), + db_size, + docs_count, + } + }); let dash_bulma_route = warp::filters::method::get() .and(warp::path!("bulma.min.css")) @@ -79,6 +106,13 @@ async fn main() -> anyhow::Result<()> { .body(include_str!("../../public/papaparse.min.js")) ); + let dash_filesize_route = warp::filters::method::get() + .and(warp::path!("filesize.min.js")) + .map(|| Response::builder() + .header("content-type", "application/javascript; charset=utf-8") + .body(include_str!("../../public/filesize.min.js")) + ); + let dash_script_route = warp::filters::method::get() .and(warp::path!("script.js")) .map(|| Response::builder() @@ -124,6 +158,7 @@ async fn main() -> anyhow::Result<()> { .or(dash_style_route) .or(dash_jquery_route) .or(dash_papaparse_route) + .or(dash_filesize_route) .or(dash_script_route) .or(query_route); diff --git a/public/index.html b/templates/index.html similarity index 86% rename from public/index.html rename to templates/index.html index 8f73eb4f7..e45569462 100644 --- a/public/index.html +++ b/templates/index.html @@ -7,7 +7,8 @@ - The milli engine + + {{ db_name }} | The milli engine @@ -20,20 +21,20 @@