fixed wasm (LaserKaspar/go-wasm-pdfcpu), migrated to vite in backend, dynamic operators on frontend
446742b7de
This commit is contained in:
@@ -5,8 +5,6 @@
|
||||
<link rel="icon" type="image/svg+xml" href="/stirling-pdf-logo.svg" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Tauri + React + TS</title>
|
||||
|
||||
<script src="browserfs.min.js"></script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
"react-icons": "^4.11.0",
|
||||
"react-router-bootstrap": "^0.26.2",
|
||||
"react-router-dom": "^6.18.0",
|
||||
"vite-plugin-node-polyfills": "^0.21.0",
|
||||
"vite-plugin-top-level-await": "^1.3.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -21,7 +21,7 @@ import resourcesToBackend from "i18next-resources-to-backend";
|
||||
|
||||
i18next.use(LanguageDetector).use(initReactI18next).use(resourcesToBackend((language: string, namespace: string) => import(`../../shared-operations/public/locales/${namespace}/${language}.json`)))
|
||||
.init({
|
||||
debug: true,
|
||||
debug: false,
|
||||
ns: ["common"], // Preload this namespace, no need to add the others, they will load once their module is loaded
|
||||
defaultNS: "common",
|
||||
fallbackLng: "en",
|
||||
|
||||
@@ -38,24 +38,15 @@ function Dynamic() {
|
||||
});
|
||||
}
|
||||
|
||||
function formDataToObject(formData: FormData): Record<string, string> {
|
||||
const result: Record<string, string> = {};
|
||||
|
||||
formData.forEach((value, key) => {
|
||||
result[key] = value.toString();
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
async function handleSubmit(e: BaseSyntheticEvent) {
|
||||
console.clear();
|
||||
if(!activeOperator.current) {
|
||||
throw new Error("Please select an Operator in the Dropdown");
|
||||
}
|
||||
|
||||
const formData = new FormData(e.target);
|
||||
|
||||
const action: Action = {type: activeOperator.current.constructor.name, values: formDataToObject(formData)};
|
||||
const values = Object.fromEntries(formData.entries());
|
||||
let action: Action = {type: activeOperator.current.type, values: values};
|
||||
|
||||
// Validate PDF File
|
||||
|
||||
@@ -68,7 +59,6 @@ function Dynamic() {
|
||||
for (let i = 0; i < files.length; i++) {
|
||||
const file = filesArray[i];
|
||||
if(file) {
|
||||
console.log(new Uint8Array(await file.arrayBuffer()));
|
||||
inputs.push(new PdfFile(
|
||||
file.name.replace(/\.[^/.]+$/, ""), // Strip Extension
|
||||
new Uint8Array(await file.arrayBuffer()),
|
||||
@@ -80,26 +70,25 @@ function Dynamic() {
|
||||
}
|
||||
}
|
||||
|
||||
const pdfValidationResults = await JoiPDFFileSchema.validate(inputs);
|
||||
if(pdfValidationResults.error) {
|
||||
console.log({error: "PDF validation failed", details: pdfValidationResults.error.message});
|
||||
}
|
||||
const pdfFiles: PdfFile[] = pdfValidationResults.value;
|
||||
const validationResults = activeOperator.current.schema.validate({input: inputs, values: action.values});
|
||||
|
||||
// Validate Action Values
|
||||
const actionValidationResults = activeOperator.current.schema.validate({input: pdfFiles, values: action.values});
|
||||
|
||||
if(actionValidationResults.error) {
|
||||
console.log({error: "Value validation failed", details: actionValidationResults.error.message});
|
||||
return;
|
||||
if(validationResults.error) {
|
||||
console.log({error: "Validation failed", details: validationResults.error.message});
|
||||
}
|
||||
else {
|
||||
action.values = validationResults.value.values;
|
||||
const operation = new activeOperator.current(action);
|
||||
operation.run(validationResults.value.input, (progress) => {}).then(async pdfFiles => {
|
||||
console.log("Done");
|
||||
console.log(pdfFiles);
|
||||
|
||||
for await (const pdfFile of (pdfFiles as PdfFile[])) {
|
||||
var blob = new Blob([await pdfFile.uint8Array], {type: "application/pdf"});
|
||||
var objectUrl = URL.createObjectURL(blob);
|
||||
window.open(objectUrl);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
action.values = pdfValidationResults.value.values;
|
||||
const operation = new activeOperator.current(action);
|
||||
|
||||
operation.run(pdfValidationResults.value, (progress) => {}).then(pdfFiles => {
|
||||
console.log("Done");
|
||||
});
|
||||
};
|
||||
|
||||
function capitalizeFirstLetter(string: String) {
|
||||
|
||||
@@ -1,14 +1,27 @@
|
||||
import { defineConfig } from "vite";
|
||||
import { nodePolyfills } from 'vite-plugin-node-polyfills'
|
||||
import react from "@vitejs/plugin-react";
|
||||
import topLevelAwait from "vite-plugin-top-level-await";
|
||||
import dynamicImport from 'vite-plugin-dynamic-import'
|
||||
import compileTime from "vite-plugin-compile-time"
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import dynamicImport from 'vite-plugin-dynamic-import';
|
||||
import compileTime from "vite-plugin-compile-time";
|
||||
import { fileURLToPath, URL } from 'node:url';
|
||||
|
||||
|
||||
// https://vitejs.dev/config/
|
||||
export default defineConfig(async () => ({
|
||||
plugins: [
|
||||
// Thanks: https://stackoverflow.com/questions/74417822/how-can-i-use-buffer-process-in-vite-app
|
||||
nodePolyfills({
|
||||
include: [],
|
||||
|
||||
globals: {
|
||||
Buffer: true, // can also be 'build', 'dev', or false
|
||||
global: false,
|
||||
process: true,
|
||||
},
|
||||
// Whether to polyfill `node:` protocol imports.
|
||||
protocolImports: false,
|
||||
}),
|
||||
react(),
|
||||
topLevelAwait({
|
||||
// The export name of top-level await promise for each chunk module
|
||||
|
||||
Reference in New Issue
Block a user