add console log panic hook
This commit is contained in:
parent
fe0c0c8737
commit
826b995ae0
5 changed files with 45 additions and 12 deletions
11
Cargo.lock
generated
11
Cargo.lock
generated
|
@ -326,6 +326,16 @@ version = "1.1.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "3d7b894f5411737b7867f4827955924d7c254fc9f4d91a6aad6b097804b1018b"
|
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]]
|
[[package]]
|
||||||
name = "cpufeatures"
|
name = "cpufeatures"
|
||||||
version = "0.2.1"
|
version = "0.2.1"
|
||||||
|
@ -1088,6 +1098,7 @@ dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"byte-unit",
|
"byte-unit",
|
||||||
"bytes",
|
"bytes",
|
||||||
|
"console_error_panic_hook",
|
||||||
"getrandom",
|
"getrandom",
|
||||||
"gloo-console",
|
"gloo-console",
|
||||||
"http",
|
"http",
|
||||||
|
|
|
@ -13,6 +13,7 @@ getrandom = { version = "*", features = ["js"] }
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
bytes = "1"
|
bytes = "1"
|
||||||
byte-unit = "4"
|
byte-unit = "4"
|
||||||
|
console_error_panic_hook = "0.1"
|
||||||
gloo-console = "0.1"
|
gloo-console = "0.1"
|
||||||
http = "0.2"
|
http = "0.2"
|
||||||
image = "0.23"
|
image = "0.23"
|
||||||
|
@ -38,5 +39,6 @@ features = [
|
||||||
"Event",
|
"Event",
|
||||||
"EventTarget",
|
"EventTarget",
|
||||||
"Window",
|
"Window",
|
||||||
|
"Performance",
|
||||||
"Location",
|
"Location",
|
||||||
]
|
]
|
|
@ -5,6 +5,7 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<title>Omegaupload</title>
|
<title>Omegaupload</title>
|
||||||
|
|
||||||
|
<link data-trunk rel="rust" data-wasm-opt="0" data-keep-debug="true" data-no-mangle="true" />
|
||||||
<link data-trunk rel="copy-file" href="vendor/MPLUS_FONTS/fonts/ttf/MplusCodeLatin[wdth,wght].ttf" dest="/" />
|
<link data-trunk rel="copy-file" href="vendor/MPLUS_FONTS/fonts/ttf/MplusCodeLatin[wdth,wght].ttf" dest="/" />
|
||||||
<link data-trunk rel="copy-file" href="vendor/highlight.min.js" dest="/" />
|
<link data-trunk rel="copy-file" href="vendor/highlight.min.js" dest="/" />
|
||||||
<link data-trunk rel="copy-file" href="vendor/highlightjs-line-numbers.js/dist/highlightjs-line-numbers.min.js"
|
<link data-trunk rel="copy-file" href="vendor/highlightjs-line-numbers.js/dist/highlightjs-line-numbers.min.js"
|
||||||
|
|
|
@ -1,8 +1,9 @@
|
||||||
use std::fmt::{Display, Formatter};
|
use std::fmt::{Display, Formatter};
|
||||||
|
use std::io::Cursor;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use gloo_console::log;
|
use gloo_console::log;
|
||||||
use image::GenericImageView;
|
use image::{EncodableLayout, GenericImageView, ImageDecoder};
|
||||||
use js_sys::{Array, Uint8Array};
|
use js_sys::{Array, Uint8Array};
|
||||||
use omegaupload_common::crypto::{open_in_place, Key, Nonce};
|
use omegaupload_common::crypto::{open_in_place, Key, Nonce};
|
||||||
use wasm_bindgen::JsCast;
|
use wasm_bindgen::JsCast;
|
||||||
|
@ -17,6 +18,14 @@ pub enum DecryptedData {
|
||||||
Video(Arc<Blob>),
|
Video(Arc<Blob>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn now() -> f64 {
|
||||||
|
web_sys::window()
|
||||||
|
.expect("should have a Window")
|
||||||
|
.performance()
|
||||||
|
.expect("should have a Performance")
|
||||||
|
.now()
|
||||||
|
}
|
||||||
|
|
||||||
pub fn decrypt(
|
pub fn decrypt(
|
||||||
mut container: Vec<u8>,
|
mut container: Vec<u8>,
|
||||||
key: Key,
|
key: Key,
|
||||||
|
@ -24,21 +33,25 @@ pub fn decrypt(
|
||||||
maybe_password: Option<Key>,
|
maybe_password: Option<Key>,
|
||||||
) -> Result<DecryptedData, PasteCompleteConstructionError> {
|
) -> Result<DecryptedData, PasteCompleteConstructionError> {
|
||||||
let container = &mut container;
|
let container = &mut container;
|
||||||
log!("stage 1 decryption start");
|
log!("Stage 1 decryption started.");
|
||||||
|
let start = now();
|
||||||
if let Some(password) = maybe_password {
|
if let Some(password) = maybe_password {
|
||||||
open_in_place(container, &nonce.increment(), &password)
|
open_in_place(container, &nonce.increment(), &password)
|
||||||
.map_err(|_| PasteCompleteConstructionError::StageOneFailure)?;
|
.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)
|
open_in_place(container, &nonce, &key)
|
||||||
.map_err(|_| PasteCompleteConstructionError::StageTwoFailure)?;
|
.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) {
|
if let Ok(decrypted) = std::str::from_utf8(container) {
|
||||||
Ok(DecryptedData::String(Arc::new(decrypted.to_owned())))
|
Ok(DecryptedData::String(Arc::new(decrypted.to_owned())))
|
||||||
} else {
|
} 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());
|
let blob_chunks = Array::new_with_length(container.chunks(65536).len().try_into().unwrap());
|
||||||
for (i, chunk) in container.chunks(65536).enumerate() {
|
for (i, chunk) in container.chunks(65536).enumerate() {
|
||||||
let array = Uint8Array::new_with_length(chunk.len().try_into().unwrap());
|
let array = Uint8Array::new_with_length(chunk.len().try_into().unwrap());
|
||||||
|
@ -47,14 +60,19 @@ pub fn decrypt(
|
||||||
}
|
}
|
||||||
let blob =
|
let blob =
|
||||||
Arc::new(Blob::new_with_u8_array_sequence(blob_chunks.dyn_ref().unwrap()).unwrap());
|
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) {
|
log!("Image introspection started");
|
||||||
Ok(DecryptedData::Image(
|
let start = now();
|
||||||
blob,
|
let res = image::guess_format(&container);
|
||||||
image.dimensions(),
|
log!(format!(
|
||||||
container.len(),
|
"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 {
|
} else {
|
||||||
let mime_type = tree_magic_mini::from_u8(container);
|
let mime_type = tree_magic_mini::from_u8(container);
|
||||||
log!(mime_type);
|
log!(mime_type);
|
||||||
|
|
|
@ -50,6 +50,7 @@ fn open_idb() -> Result<IdbOpenDbRequest> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
std::panic::set_hook(Box::new(console_error_panic_hook::hook));
|
||||||
let url = String::from(location().to_string());
|
let url = String::from(location().to_string());
|
||||||
let request_uri = {
|
let request_uri = {
|
||||||
let mut uri_parts = url.parse::<Uri>().unwrap().into_parts();
|
let mut uri_parts = url.parse::<Uri>().unwrap().into_parts();
|
||||||
|
|
Loading…
Reference in a new issue