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]
|
#[wasm_bindgen]
|
||||||
#[allow(clippy::future_not_send)]
|
#[allow(clippy::future_not_send)]
|
||||||
#[allow(clippy::missing_panics_doc)]
|
|
||||||
pub fn encrypt_string(data: String) {
|
pub fn encrypt_string(data: String) {
|
||||||
spawn_local(async move {
|
spawn_local(async move {
|
||||||
if let Err(e) = do_encrypt(data.into_bytes()).await {
|
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)]
|
#[allow(clippy::future_not_send)]
|
||||||
async fn do_encrypt(mut data: Vec<u8>) -> Result<()> {
|
async fn do_encrypt(mut data: Vec<u8>) -> Result<()> {
|
||||||
let (data, key) = {
|
let (data, key) = {
|
||||||
|
|
|
@ -17,12 +17,31 @@
|
||||||
import './main.scss';
|
import './main.scss';
|
||||||
import ReactDom from 'react-dom';
|
import ReactDom from 'react-dom';
|
||||||
import React, { useState } from 'react';
|
import React, { useState } from 'react';
|
||||||
import { encrypt_string } from '../pkg';
|
import { encrypt_string, encrypt_array_buffer } from '../pkg';
|
||||||
|
|
||||||
import hljs from 'highlight.js'
|
import hljs from 'highlight.js'
|
||||||
(window as any).hljs = hljs;
|
(window as any).hljs = hljs;
|
||||||
require('highlightjs-line-numbers.js');
|
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 PasteForm = () => {
|
||||||
const [value, setValue] = useState("");
|
const [value, setValue] = useState("");
|
||||||
|
|
||||||
|
@ -47,6 +66,7 @@ const PasteForm = () => {
|
||||||
|
|
||||||
function createUploadUi() {
|
function createUploadUi() {
|
||||||
const html = <main className='hljs centered fullscreen'>
|
const html = <main className='hljs centered fullscreen'>
|
||||||
|
<FileForm />
|
||||||
<PasteForm />
|
<PasteForm />
|
||||||
</main>;
|
</main>;
|
||||||
|
|
||||||
|
@ -54,7 +74,7 @@ function createUploadUi() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadFromDb(mimeType: string, name?: string, language?: string) {
|
function loadFromDb(mimeType: string, name?: string, language?: string) {
|
||||||
let resolvedName;
|
let resolvedName: string;
|
||||||
if (name) {
|
if (name) {
|
||||||
resolvedName = name;
|
resolvedName = name;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue