diff --git a/Cargo.lock b/Cargo.lock index cccd702..c7aeef8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -326,6 +326,16 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b" +[[package]] +name = "console_error_panic_hook" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a06aeb73f470f66dcdbf7223caeebb85984942f22f1adb2a088cf9668146bbbc" +dependencies = [ + "cfg-if", + "wasm-bindgen", +] + [[package]] name = "cpufeatures" version = "0.2.1" @@ -1088,6 +1098,7 @@ dependencies = [ "anyhow", "byte-unit", "bytes", + "console_error_panic_hook", "getrandom", "gloo-console", "http", diff --git a/web/Cargo.toml b/web/Cargo.toml index 53758bc..ae29957 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -13,6 +13,7 @@ getrandom = { version = "*", features = ["js"] } anyhow = "1" bytes = "1" byte-unit = "4" +console_error_panic_hook = "0.1" gloo-console = "0.1" http = "0.2" image = "0.23" @@ -38,5 +39,6 @@ features = [ "Event", "EventTarget", "Window", + "Performance", "Location", ] \ No newline at end of file diff --git a/web/index.html b/web/index.html index 7c85220..a6fdaf5 100644 --- a/web/index.html +++ b/web/index.html @@ -5,6 +5,7 @@ Omegaupload + ), } +fn now() -> f64 { + web_sys::window() + .expect("should have a Window") + .performance() + .expect("should have a Performance") + .now() +} + pub fn decrypt( mut container: Vec, key: Key, @@ -24,21 +33,25 @@ pub fn decrypt( maybe_password: Option, ) -> Result { let container = &mut container; - log!("stage 1 decryption start"); + log!("Stage 1 decryption started."); + let start = now(); if let Some(password) = maybe_password { open_in_place(container, &nonce.increment(), &password) .map_err(|_| PasteCompleteConstructionError::StageOneFailure)?; } + log!(format!("Stage 1 completed in {}ms", now() - start)); - log!("stage 2 decryption start"); + log!("Stage 2 decryption started."); + let start = now(); open_in_place(container, &nonce, &key) .map_err(|_| PasteCompleteConstructionError::StageTwoFailure)?; + log!(format!("Stage 2 completed in {}ms", now() - start)); - log!("stage 2 decryption end"); if let Ok(decrypted) = std::str::from_utf8(container) { Ok(DecryptedData::String(Arc::new(decrypted.to_owned()))) } else { - log!("blob conversion start"); + log!("Blob conversion started."); + let start = now(); let blob_chunks = Array::new_with_length(container.chunks(65536).len().try_into().unwrap()); for (i, chunk) in container.chunks(65536).enumerate() { let array = Uint8Array::new_with_length(chunk.len().try_into().unwrap()); @@ -47,14 +60,19 @@ pub fn decrypt( } let blob = Arc::new(Blob::new_with_u8_array_sequence(blob_chunks.dyn_ref().unwrap()).unwrap()); - log!("blob conversion end"); + log!(format!("Blob conversion completed in {}ms", now() - start)); - if let Ok(image) = image::load_from_memory(container) { - Ok(DecryptedData::Image( - blob, - image.dimensions(), - container.len(), - )) + log!("Image introspection started"); + let start = now(); + let res = image::guess_format(&container); + log!(format!( + "Image introspection completed in {}ms", + now() - start + )); + // let image_reader = image::io::Reader::new(Cursor::new(container.as_bytes())); + if let Ok(dimensions) = res { + log!(format!("{:?}", dimensions)); + Ok(DecryptedData::Image(blob, (0, 0), container.len())) } else { let mime_type = tree_magic_mini::from_u8(container); log!(mime_type); diff --git a/web/src/main.rs b/web/src/main.rs index 2820dc6..b46dba0 100644 --- a/web/src/main.rs +++ b/web/src/main.rs @@ -50,6 +50,7 @@ fn open_idb() -> Result { } fn main() { + std::panic::set_hook(Box::new(console_error_panic_hook::hook)); let url = String::from(location().to_string()); let request_uri = { let mut uri_parts = url.parse::().unwrap().into_parts();