support file upload, fix some lints
This commit is contained in:
parent
37bdbae640
commit
a9e9a93493
2 changed files with 32 additions and 3 deletions
|
@ -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<u8>) {
|
||||
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<u8>) -> Result<()> {
|
||||
let (data, key) = {
|
||||
|
|
|
@ -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<HTMLInputElement>) => {
|
||||
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 (
|
||||
<input type="file" onChange={handleChange} />
|
||||
)
|
||||
}
|
||||
|
||||
const PasteForm = () => {
|
||||
const [value, setValue] = useState("");
|
||||
|
||||
|
@ -47,6 +66,7 @@ const PasteForm = () => {
|
|||
|
||||
function createUploadUi() {
|
||||
const html = <main className='hljs centered fullscreen'>
|
||||
<FileForm />
|
||||
<PasteForm />
|
||||
</main>;
|
||||
|
||||
|
@ -54,7 +74,7 @@ function createUploadUi() {
|
|||
}
|
||||
|
||||
function loadFromDb(mimeType: string, name?: string, language?: string) {
|
||||
let resolvedName;
|
||||
let resolvedName: string;
|
||||
if (name) {
|
||||
resolvedName = name;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue