Get rid of yew completely
This commit is contained in:
parent
95e15b81b7
commit
23b90ebfe4
4 changed files with 218 additions and 515 deletions
217
Cargo.lock
generated
217
Cargo.lock
generated
|
@ -47,18 +47,6 @@ version = "1.0.44"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61604a8f862e1d5c3229fdd78f8b02c68dcf73a4c4b05fd636d12240aaa242c1"
|
||||
|
||||
[[package]]
|
||||
name = "anymap"
|
||||
version = "0.12.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "33954243bd79057c2de7338850b85983a44588021f8a5fee574a8888c6de4344"
|
||||
|
||||
[[package]]
|
||||
name = "arrayvec"
|
||||
version = "0.5.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
|
||||
|
||||
[[package]]
|
||||
name = "async-trait"
|
||||
version = "0.1.51"
|
||||
|
@ -176,12 +164,6 @@ dependencies = [
|
|||
"generic-array",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "boolinator"
|
||||
version = "2.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cfa8873f51c92e232f9bac4065cddef41b714152812bfc5f7672ba16d6ef8cd9"
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.7.1"
|
||||
|
@ -248,12 +230,6 @@ version = "1.0.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-match"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8100e46ff92eb85bf6dc2930c73f2a4f7176393c84a9446b3d501e1b354e7b34"
|
||||
|
||||
[[package]]
|
||||
name = "chacha20"
|
||||
version = "0.8.1"
|
||||
|
@ -350,16 +326,6 @@ 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"
|
||||
|
@ -617,18 +583,6 @@ version = "0.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
|
||||
[[package]]
|
||||
name = "gloo"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68ce6f2dfa9f57f15b848efa2aade5e1850dc72986b87a2b0752d44ca08f4967"
|
||||
dependencies = [
|
||||
"gloo-console-timer",
|
||||
"gloo-events",
|
||||
"gloo-file",
|
||||
"gloo-timers",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-console"
|
||||
version = "0.1.0"
|
||||
|
@ -641,48 +595,6 @@ dependencies = [
|
|||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-console-timer"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b48675544b29ac03402c6dffc31a912f716e38d19f7e74b78b7e900ec3c941ea"
|
||||
dependencies = [
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-events"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "088514ec8ef284891c762c88a66b639b3a730134714692ee31829765c5bc814f"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-file"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f9fecfe46b5dc3cc46f58e98ba580cc714f2c93860796d002eb3527a465ef49"
|
||||
dependencies = [
|
||||
"gloo-events",
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "gloo-timers"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47204a46aaff920a1ea58b11d03dec6f704287d27561724a4631e450654a891f"
|
||||
dependencies = [
|
||||
"js-sys",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "h2"
|
||||
version = "0.3.6"
|
||||
|
@ -915,19 +827,6 @@ version = "1.3.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
|
||||
|
||||
[[package]]
|
||||
name = "lexical-core"
|
||||
version = "0.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitflags",
|
||||
"cfg-if",
|
||||
"ryu",
|
||||
"static_assertions",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.103"
|
||||
|
@ -1048,17 +947,6 @@ dependencies = [
|
|||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "5.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ffb4262d26ed83a1c0a33a38fe2bb15797329c85770da05e6b828ddb782627af"
|
||||
dependencies = [
|
||||
"lexical-core",
|
||||
"memchr",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nom"
|
||||
version = "6.1.2"
|
||||
|
@ -1207,9 +1095,6 @@ dependencies = [
|
|||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"yew",
|
||||
"yew-router",
|
||||
"yewtil",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1711,12 +1596,6 @@ version = "0.5.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
|
||||
|
||||
[[package]]
|
||||
name = "static_assertions"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
|
@ -2286,102 +2165,6 @@ version = "0.2.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
|
||||
|
||||
[[package]]
|
||||
name = "yew"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e4d5154faef86dddd2eb333d4755ea5643787d20aca683e58759b0e53351409f"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"anymap",
|
||||
"bincode",
|
||||
"cfg-if",
|
||||
"cfg-match",
|
||||
"console_error_panic_hook",
|
||||
"gloo",
|
||||
"http",
|
||||
"indexmap",
|
||||
"js-sys",
|
||||
"log",
|
||||
"ryu",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"slab",
|
||||
"thiserror",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"yew-macro",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yew-macro"
|
||||
version = "0.18.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6e23bfe3dc3933fbe9592d149c9985f3047d08c637a884b9344c21e56e092ef"
|
||||
dependencies = [
|
||||
"boolinator",
|
||||
"lazy_static",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yew-router"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "27666236d9597eac9be560e841e415e20ba67020bc8cd081076be178e159c8bc"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"cfg-match",
|
||||
"gloo",
|
||||
"js-sys",
|
||||
"log",
|
||||
"nom 5.1.2",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"wasm-bindgen",
|
||||
"web-sys",
|
||||
"yew",
|
||||
"yew-router-macro",
|
||||
"yew-router-route-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yew-router-macro"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4c0ace2924b7a175e2d1c0e62ee7022a5ad840040dcd52414ce5f410ab322dba"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"yew-router-route-parser",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yew-router-route-parser"
|
||||
version = "0.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "de4a67208fb46b900af18a7397938b01f379dfc18da34799cfa8347eec715697"
|
||||
dependencies = [
|
||||
"nom 5.1.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "yewtil"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8543663ac49cd613df079282a1d8bdbdebdad6e02bac229f870fd4237b5d9aaa"
|
||||
dependencies = [
|
||||
"log",
|
||||
"wasm-bindgen",
|
||||
"wasm-bindgen-futures",
|
||||
"web-sys",
|
||||
"yew",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zeroize"
|
||||
version = "1.4.2"
|
||||
|
|
|
@ -20,9 +20,6 @@ reqwasm = "0.2"
|
|||
tree_magic_mini = { version = "3", features = ["with-gpl-data"] }
|
||||
wasm-bindgen = "0.2"
|
||||
wasm-bindgen-futures = "0.4"
|
||||
yew = { version = "0.18", features = ["wasm-bindgen-futures"] }
|
||||
yew-router = "0.15"
|
||||
yewtil = "0.4"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3"
|
||||
|
@ -38,5 +35,7 @@ features = [
|
|||
"IdbIndex",
|
||||
"IdbIndexParameters",
|
||||
"Event",
|
||||
"EventTarget"
|
||||
"EventTarget",
|
||||
"Window",
|
||||
"Location",
|
||||
]
|
|
@ -35,28 +35,28 @@ pub fn decrypt(
|
|||
.map_err(|_| PasteCompleteConstructionError::StageTwoFailure)?;
|
||||
|
||||
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())))
|
||||
} else {
|
||||
log!("blob conversion start");
|
||||
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());
|
||||
array.copy_from(&chunk);
|
||||
array.copy_from(chunk);
|
||||
blob_chunks.set(i.try_into().unwrap(), array.dyn_into().unwrap());
|
||||
}
|
||||
let blob =
|
||||
Arc::new(Blob::new_with_u8_array_sequence(blob_chunks.dyn_ref().unwrap()).unwrap());
|
||||
log!("blob conversion end");
|
||||
|
||||
if let Ok(image) = image::load_from_memory(&container) {
|
||||
if let Ok(image) = image::load_from_memory(container) {
|
||||
Ok(DecryptedData::Image(
|
||||
blob,
|
||||
image.dimensions(),
|
||||
container.len(),
|
||||
))
|
||||
} else {
|
||||
let mime_type = tree_magic_mini::from_u8(&container);
|
||||
let mime_type = tree_magic_mini::from_u8(container);
|
||||
log!(mime_type);
|
||||
if mime_type.starts_with("audio/") {
|
||||
Ok(DecryptedData::Audio(blob))
|
||||
|
|
501
web/src/main.rs
501
web/src/main.rs
|
@ -1,8 +1,6 @@
|
|||
#![warn(clippy::nursery, clippy::pedantic)]
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
|
||||
use byte_unit::Byte;
|
||||
use decrypt::DecryptedData;
|
||||
|
@ -15,313 +13,236 @@ use omegaupload_common::{Expiration, PartialParsedUrl};
|
|||
use reqwasm::http::Request;
|
||||
use wasm_bindgen::prelude::{wasm_bindgen, Closure};
|
||||
use wasm_bindgen::{JsCast, JsValue};
|
||||
use wasm_bindgen_futures::JsFuture;
|
||||
use web_sys::{Blob, Event, IdbDatabase, IdbObjectStore, IdbOpenDbRequest, IdbTransactionMode};
|
||||
use yew::utils::window;
|
||||
use yew::{html, Component, ComponentLink, Html, ShouldRender};
|
||||
use yew_router::router::Router;
|
||||
use yew_router::Switch;
|
||||
use yewtil::future::LinkFuture;
|
||||
use wasm_bindgen_futures::{spawn_local, JsFuture};
|
||||
use web_sys::{window, Event, IdbDatabase, IdbObjectStore, IdbOpenDbRequest, IdbTransactionMode};
|
||||
|
||||
use crate::decrypt::decrypt;
|
||||
|
||||
mod decrypt;
|
||||
|
||||
fn main() {
|
||||
yew::start_app::<App>();
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
extern "C" {
|
||||
fn loadFromDb();
|
||||
fn createNotFoundUi();
|
||||
}
|
||||
|
||||
struct App;
|
||||
impl Component for App {
|
||||
type Message = ();
|
||||
type Properties = ();
|
||||
|
||||
fn create(_: Self::Properties, _: ComponentLink<Self>) -> Self {
|
||||
Self
|
||||
}
|
||||
|
||||
fn update(&mut self, _: Self::Message) -> ShouldRender {
|
||||
false
|
||||
}
|
||||
|
||||
fn change(&mut self, _props: Self::Properties) -> ShouldRender {
|
||||
false
|
||||
}
|
||||
|
||||
fn view(&self) -> Html {
|
||||
html! {
|
||||
<Router<Route> render={Router::render(render_route)} />
|
||||
fn main() {
|
||||
let window = window().unwrap();
|
||||
let url = String::from(window.location().to_string());
|
||||
let request_uri = {
|
||||
let mut uri_parts = url.parse::<Uri>().unwrap().into_parts();
|
||||
if let Some(parts) = uri_parts.path_and_query.as_mut() {
|
||||
*parts = PathAndQuery::from_str(&format!("/api{}", parts.path())).unwrap();
|
||||
}
|
||||
Uri::from_parts(uri_parts).unwrap()
|
||||
};
|
||||
|
||||
if window.location().pathname().unwrap() == "/" {
|
||||
} else {
|
||||
spawn_local(a(request_uri, url));
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Switch)]
|
||||
enum Route {
|
||||
#[to = "/!"]
|
||||
Index,
|
||||
#[rest]
|
||||
Path(String),
|
||||
}
|
||||
#[allow(clippy::future_not_send)]
|
||||
async fn a(request_uri: Uri, url: String) {
|
||||
match Request::get(&request_uri.to_string()).send().await {
|
||||
Ok(resp) if resp.status() == StatusCode::OK => {
|
||||
let expires = resp
|
||||
.headers()
|
||||
.get(EXPIRES.as_str())
|
||||
.ok()
|
||||
.flatten()
|
||||
.as_deref()
|
||||
.and_then(|v| Expiration::try_from(v).ok())
|
||||
.as_ref()
|
||||
.map_or_else(
|
||||
|| "This item does not expire.".to_string(),
|
||||
Expiration::to_string,
|
||||
);
|
||||
|
||||
#[allow(clippy::needless_pass_by_value)]
|
||||
fn render_route(route: Route) -> Html {
|
||||
match route {
|
||||
Route::Index => html! {
|
||||
<main>
|
||||
<p>{ "Hello world" }</p>
|
||||
</main>
|
||||
},
|
||||
Route::Path(_) => html! {
|
||||
<>
|
||||
<Paste/>
|
||||
<section class="hljs fullscreen centered">
|
||||
<p>{"Loading"}</p>
|
||||
</section>
|
||||
</>
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Paste;
|
||||
|
||||
impl Component for Paste {
|
||||
type Message = ();
|
||||
type Properties = ();
|
||||
|
||||
fn create(_: Self::Properties, link: ComponentLink<Self>) -> Self {
|
||||
let url = String::from(window().location().to_string());
|
||||
let request_uri = {
|
||||
let mut uri_parts = url.parse::<Uri>().unwrap().into_parts();
|
||||
if let Some(parts) = uri_parts.path_and_query.as_mut() {
|
||||
*parts = PathAndQuery::from_str(&format!("/api{}", parts.path())).unwrap();
|
||||
}
|
||||
Uri::from_parts(uri_parts).unwrap()
|
||||
};
|
||||
|
||||
link.send_future(async move {
|
||||
match Request::get(&request_uri.to_string()).send().await {
|
||||
Ok(resp) if resp.status() == StatusCode::OK => {
|
||||
let expires = resp
|
||||
.headers()
|
||||
.get(EXPIRES.as_str())
|
||||
.ok()
|
||||
.flatten()
|
||||
.as_deref()
|
||||
.and_then(|v| Expiration::try_from(v).ok())
|
||||
.as_ref()
|
||||
.map(Expiration::to_string)
|
||||
.unwrap_or_else(|| "This item does not expire.".to_string());
|
||||
|
||||
let data = {
|
||||
Uint8Array::new(
|
||||
&JsFuture::from(resp.as_raw().array_buffer().unwrap())
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.to_vec()
|
||||
};
|
||||
|
||||
let info = url
|
||||
.split_once('#')
|
||||
.map(|(_, fragment)| PartialParsedUrl::from(fragment))
|
||||
.unwrap_or_default();
|
||||
let key = info.decryption_key.unwrap();
|
||||
let nonce = info.nonce.unwrap();
|
||||
|
||||
let result = decrypt(data, key, nonce, None);
|
||||
|
||||
let decrypted = match result {
|
||||
Ok(decrypted) => decrypted,
|
||||
Err(err) => {
|
||||
// log!("decryption error: {}", err);
|
||||
// return Box::new(PasteError(err));
|
||||
unimplemented!()
|
||||
}
|
||||
};
|
||||
|
||||
let db_open_req = window()
|
||||
.indexed_db()
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.open("omegaupload")
|
||||
.unwrap();
|
||||
|
||||
// On success callback
|
||||
let on_success = Closure::once(Box::new(move |event: Event| {
|
||||
let target: IdbOpenDbRequest = event.target().unwrap().dyn_into().unwrap();
|
||||
let db: IdbDatabase = target.result().unwrap().dyn_into().unwrap();
|
||||
let transaction: IdbObjectStore = db
|
||||
.transaction_with_str_and_mode(
|
||||
"decrypted data",
|
||||
IdbTransactionMode::Readwrite,
|
||||
)
|
||||
.unwrap()
|
||||
.object_store("decrypted data")
|
||||
.unwrap();
|
||||
|
||||
let decrypted_object = Array::new();
|
||||
match &decrypted {
|
||||
DecryptedData::String(s) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(&JsValue::from_str(&s));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("string"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Blob(blob) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("blob"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Image(blob, (width, height), size) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("image"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("width"));
|
||||
entry.push(&JsValue::from(*width));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("height"));
|
||||
entry.push(&JsValue::from(*height));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("button"));
|
||||
entry.push(&JsString::from(format!(
|
||||
"Download {} \u{2014} {} by {}",
|
||||
Byte::from_bytes(*size as u128).get_appropriate_unit(true),
|
||||
width,
|
||||
height,
|
||||
)));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Audio(blob) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("audio"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Video(blob) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("video"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
}
|
||||
|
||||
let db_entry = Object::from_entries(&decrypted_object).unwrap();
|
||||
transaction
|
||||
.put_with_key(
|
||||
&db_entry,
|
||||
&JsString::from(window().location().pathname().unwrap()),
|
||||
)
|
||||
.unwrap()
|
||||
.set_onsuccess(Some(
|
||||
Closure::once(Box::new(|| {
|
||||
log!("success");
|
||||
loadFromDb();
|
||||
})
|
||||
as Box<dyn FnOnce()>)
|
||||
.into_js_value()
|
||||
.dyn_ref()
|
||||
.unwrap(),
|
||||
));
|
||||
})
|
||||
as Box<dyn FnOnce(Event)>);
|
||||
|
||||
db_open_req.set_onsuccess(Some(on_success.into_js_value().dyn_ref().unwrap()));
|
||||
|
||||
// On upgrade callback
|
||||
let on_upgrade = Closure::wrap(Box::new(move |event: Event| {
|
||||
let target: IdbOpenDbRequest = event.target().unwrap().dyn_into().unwrap();
|
||||
let db: IdbDatabase = target.result().unwrap().dyn_into().unwrap();
|
||||
let _obj_store = db.create_object_store("decrypted data").unwrap();
|
||||
}) as Box<dyn FnMut(Event)>);
|
||||
|
||||
db_open_req
|
||||
.set_onupgradeneeded(Some(on_upgrade.into_js_value().dyn_ref().unwrap()));
|
||||
}
|
||||
Ok(resp) if resp.status() == StatusCode::NOT_FOUND => {
|
||||
createNotFoundUi();
|
||||
}
|
||||
Ok(resp) if resp.status() == StatusCode::BAD_REQUEST => {}
|
||||
Ok(err) => {}
|
||||
Err(err) => {}
|
||||
let data = {
|
||||
Uint8Array::new(
|
||||
&JsFuture::from(resp.as_raw().array_buffer().unwrap())
|
||||
.await
|
||||
.unwrap(),
|
||||
)
|
||||
.to_vec()
|
||||
};
|
||||
});
|
||||
|
||||
Self
|
||||
}
|
||||
let info = url
|
||||
.split_once('#')
|
||||
.map(|(_, fragment)| PartialParsedUrl::from(fragment))
|
||||
.unwrap_or_default();
|
||||
let key = info.decryption_key.unwrap();
|
||||
let nonce = info.nonce.unwrap();
|
||||
|
||||
fn update(&mut self, _: Self::Message) -> ShouldRender {
|
||||
false
|
||||
}
|
||||
let result = decrypt(data, key, nonce, None);
|
||||
|
||||
fn change(&mut self, _: Self::Properties) -> ShouldRender {
|
||||
false
|
||||
}
|
||||
let decrypted = match result {
|
||||
Ok(decrypted) => decrypted,
|
||||
Err(err) => {
|
||||
// log!("decryption error: {}", err);
|
||||
// return Box::new(PasteError(err));
|
||||
unimplemented!()
|
||||
}
|
||||
};
|
||||
|
||||
fn view(&self) -> Html {
|
||||
html! {}
|
||||
}
|
||||
let db_open_req = window()
|
||||
.unwrap()
|
||||
.indexed_db()
|
||||
.unwrap()
|
||||
.unwrap()
|
||||
.open("omegaupload")
|
||||
.unwrap();
|
||||
|
||||
// On success callback
|
||||
let on_success = Closure::once(Box::new(move |event: Event| {
|
||||
let target: IdbOpenDbRequest = event.target().unwrap().dyn_into().unwrap();
|
||||
let db: IdbDatabase = target.result().unwrap().dyn_into().unwrap();
|
||||
let transaction: IdbObjectStore = db
|
||||
.transaction_with_str_and_mode("decrypted data", IdbTransactionMode::Readwrite)
|
||||
.unwrap()
|
||||
.object_store("decrypted data")
|
||||
.unwrap();
|
||||
|
||||
let decrypted_object = Array::new();
|
||||
match &decrypted {
|
||||
DecryptedData::String(s) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(&JsValue::from_str(s));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("string"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Blob(blob) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("blob"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Image(blob, (width, height), size) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("image"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("width"));
|
||||
entry.push(&JsValue::from(*width));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("height"));
|
||||
entry.push(&JsValue::from(*height));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("button"));
|
||||
entry.push(&JsString::from(format!(
|
||||
"Download {} \u{2014} {} by {}",
|
||||
Byte::from_bytes(*size as u128).get_appropriate_unit(true),
|
||||
width,
|
||||
height,
|
||||
)));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Audio(blob) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("audio"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
DecryptedData::Video(blob) => {
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("data"));
|
||||
entry.push(blob);
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("type"));
|
||||
entry.push(&JsString::from("video"));
|
||||
decrypted_object.push(&entry);
|
||||
|
||||
let entry = Array::new();
|
||||
entry.push(&JsString::from("expiration"));
|
||||
entry.push(&JsString::from(expires.to_string()));
|
||||
decrypted_object.push(&entry);
|
||||
}
|
||||
}
|
||||
|
||||
let db_entry = Object::from_entries(&decrypted_object).unwrap();
|
||||
transaction
|
||||
.put_with_key(
|
||||
&db_entry,
|
||||
&JsString::from(window().unwrap().location().pathname().unwrap()),
|
||||
)
|
||||
.unwrap()
|
||||
.set_onsuccess(Some(
|
||||
Closure::once(Box::new(|| {
|
||||
log!("success");
|
||||
loadFromDb();
|
||||
}) as Box<dyn FnOnce()>)
|
||||
.into_js_value()
|
||||
.dyn_ref()
|
||||
.unwrap(),
|
||||
));
|
||||
}) as Box<dyn FnOnce(Event)>);
|
||||
|
||||
db_open_req.set_onsuccess(Some(on_success.into_js_value().dyn_ref().unwrap()));
|
||||
|
||||
// On upgrade callback
|
||||
let on_upgrade = Closure::wrap(Box::new(move |event: Event| {
|
||||
let target: IdbOpenDbRequest = event.target().unwrap().dyn_into().unwrap();
|
||||
let db: IdbDatabase = target.result().unwrap().dyn_into().unwrap();
|
||||
let _obj_store = db.create_object_store("decrypted data").unwrap();
|
||||
}) as Box<dyn FnMut(Event)>);
|
||||
|
||||
db_open_req.set_onupgradeneeded(Some(on_upgrade.into_js_value().dyn_ref().unwrap()));
|
||||
}
|
||||
Ok(resp) if resp.status() == StatusCode::NOT_FOUND => {
|
||||
createNotFoundUi();
|
||||
}
|
||||
Ok(resp) if resp.status() == StatusCode::BAD_REQUEST => {}
|
||||
Ok(err) => {}
|
||||
Err(err) => {}
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue