support file upload, fix some lints

master
Ninja3047 2022-07-27 17:36:15 -04:00
parent 37bdbae640
commit a9e9a93493
No known key found for this signature in database
2 changed files with 32 additions and 3 deletions

View File

@ -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) = {

View File

@ -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 {