diff --git a/web/src/lib.rs b/web/src/lib.rs index 67813aa..ff09e37 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -173,7 +173,6 @@ pub fn start() { #[wasm_bindgen] #[allow(clippy::future_not_send)] -#[allow(clippy::missing_panics_doc)] pub fn encrypt_string(data: String) { spawn_local(async move { if let Err(e) = do_encrypt(data.into_bytes()).await { @@ -182,6 +181,16 @@ pub fn encrypt_string(data: String) { }); } +#[wasm_bindgen] +#[allow(clippy::future_not_send)] +pub fn encrypt_array_buffer(data: Vec) { + spawn_local(async move { + if let Err(e) = do_encrypt(data).await { + log!(format!("[rs] Error encrypting array buffer: {}", e)); + } + }); +} + #[allow(clippy::future_not_send)] async fn do_encrypt(mut data: Vec) -> Result<()> { let (data, key) = { diff --git a/web/src/render.tsx b/web/src/render.tsx index 6ce209a..9374cb0 100644 --- a/web/src/render.tsx +++ b/web/src/render.tsx @@ -17,12 +17,31 @@ import './main.scss'; import ReactDom from 'react-dom'; import React, { useState } from 'react'; -import { encrypt_string } from '../pkg'; +import { encrypt_string, encrypt_array_buffer } from '../pkg'; import hljs from 'highlight.js' (window as any).hljs = hljs; require('highlightjs-line-numbers.js'); +const FileForm = () => { + const handleChange = (event: React.ChangeEvent) => { + const fr = new FileReader(); + fr.onload = (e) => { + const { result } = e.target; + if (result instanceof ArrayBuffer) { + console.log("File uploaded"); + let data = new Uint8Array(result); + encrypt_array_buffer(data); + } + } + fr.readAsArrayBuffer((event.target as HTMLInputElement).files[0]); + } + + return ( + + ) +} + const PasteForm = () => { const [value, setValue] = useState(""); @@ -47,6 +66,7 @@ const PasteForm = () => { function createUploadUi() { const html =
+
; @@ -54,7 +74,7 @@ function createUploadUi() { } function loadFromDb(mimeType: string, name?: string, language?: string) { - let resolvedName; + let resolvedName: string; if (name) { resolvedName = name; } else {