diff --git a/public/dep/downloadjs_1.4.7.js b/client-vanilla/dep/downloadjs_1.4.7.js similarity index 100% rename from public/dep/downloadjs_1.4.7.js rename to client-vanilla/dep/downloadjs_1.4.7.js diff --git a/public/dep/jsQR.js b/client-vanilla/dep/jsQR.js similarity index 100% rename from public/dep/jsQR.js rename to client-vanilla/dep/jsQR.js diff --git a/public/dep/pdf-lib.min.js b/client-vanilla/dep/pdf-lib.min.js similarity index 100% rename from public/dep/pdf-lib.min.js rename to client-vanilla/dep/pdf-lib.min.js diff --git a/public/dep/pdf.min.js b/client-vanilla/dep/pdf.min.js similarity index 100% rename from public/dep/pdf.min.js rename to client-vanilla/dep/pdf.min.js diff --git a/public/dep/pdf.worker.min.js b/client-vanilla/dep/pdf.worker.min.js similarity index 100% rename from public/dep/pdf.worker.min.js rename to client-vanilla/dep/pdf.worker.min.js diff --git a/public/exampleWorkflows.js b/client-vanilla/exampleWorkflows.js similarity index 100% rename from public/exampleWorkflows.js rename to client-vanilla/exampleWorkflows.js diff --git a/public/functions.js b/client-vanilla/functions.js similarity index 95% rename from public/functions.js rename to client-vanilla/functions.js index cfdbabc71..944ba702b 100644 --- a/public/functions.js +++ b/client-vanilla/functions.js @@ -2,7 +2,8 @@ // PDFJS as pdfjsLib via index.html script-tag // jsQR via index.html script-tag -import * as pdfcpuWraopper from "./wasm/pdfcpu-wrapper-browser.js"; +import * as pdfcpuWraopper from "./wasm/pdfcpu/pdfcpu-wrapper-browser.js"; + const OpenCV = { cv: cv } // OPENCV gets importet as cv via index.html script-tag import { extractPages as dependantExtractPages } from "./functions/extractPages.js"; @@ -17,6 +18,8 @@ import { organizePages as dependantOrganizePages} from "./functions/organizePage import { removeBlankPages as dependantRemoveBlankPages} from "./functions/removeBlankPages.js"; import { splitOn as dependantSplitOn } from "./functions/splitOn.js"; +// TODO: Dynamic loading & undloading of libraries. + export async function extractPages(snapshot, pagesToExtractArray) { return dependantExtractPages(snapshot, pagesToExtractArray, PDFLib); } diff --git a/public/index.css b/client-vanilla/index.css similarity index 100% rename from public/index.css rename to client-vanilla/index.css diff --git a/public/index.html b/client-vanilla/index.html similarity index 100% rename from public/index.html rename to client-vanilla/index.html diff --git a/public/index.js b/client-vanilla/index.js similarity index 98% rename from public/index.js rename to client-vanilla/index.js index 4a2f5e467..741ba0aad 100644 --- a/public/index.js +++ b/client-vanilla/index.js @@ -12,7 +12,6 @@ import * as Functions from "./functions.js"; console.log("Starting..."); const files = Array.from(pdfFileInput.files); - console.log(files); const inputs = await Promise.all(files.map(async file => { return { originalFileName: file.name.replace(/\.[^/.]+$/, ""), diff --git a/index.js b/index.js index cf6c87add..024e98b1c 100644 --- a/index.js +++ b/index.js @@ -1,12 +1,13 @@ -import api from './routes/api/index.js'; +import api from './server-node/routes/api/index.js'; import express from 'express'; const app = express(); const PORT = 8080; // Static Middleware -app.use(express.static('./public')); +app.use(express.static('./client-vanilla')); +app.use(express.static('./shared-operations')); app.get('/', function (req, res, next) { // TODO: Use EJS? res.render('home.ejs'); diff --git a/functions.js b/server-node/functions.js similarity index 59% rename from functions.js rename to server-node/functions.js index fcc848d4b..29d771d5f 100644 --- a/functions.js +++ b/server-node/functions.js @@ -3,20 +3,20 @@ import PDFJS from "pdfjs-dist"; import jsQR from "jsqr"; delete global.crypto; // TODO: I hate to do this, but the new node version forces me to, if anyone finds a better solution, please tell me! -import * as pdfcpuWraopper from "./public/wasm/pdfcpu-wrapper-node.js"; +import * as pdfcpuWraopper from "../shared-operations/wasm/pdfcpu/pdfcpu-wrapper-node.js"; import OpenCV from 'opencv-wasm'; -import { extractPages as dependantExtractPages } from "./public/functions/extractPages.js"; -import { impose as dependantImpose } from './public/functions/impose.js'; -import { mergePDFs as dependantMergePDFs } from './public/functions/mergePDFs.js'; -import { rotatePages as dependantRotatePages } from './public/functions/rotatePages.js'; -import { scaleContent as dependantScaleContent} from './public/functions/scaleContent.js'; -import { scalePage as dependantScalePage } from './public/functions/scalePage.js'; -import { splitPDF as dependantSplitPDF } from './public/functions/splitPDF.js'; -import { editMetadata as dependantEditMetadata } from './public/functions/editMetadata.js'; -import { organizePages as dependantOrganizePages } from './public/functions/organizePages.js'; -import { removeBlankPages as dependantRemoveBlankPages} from './public/functions/removeBlankPages.js'; -import { splitOn as dependantSplitOn } from "./public/functions/splitOn.js"; +import { extractPages as dependantExtractPages } from "../shared-operations/functions/extractPages.js"; +import { impose as dependantImpose } from '../shared-operations/functions/impose.js'; +import { mergePDFs as dependantMergePDFs } from '../shared-operations/functions/mergePDFs.js'; +import { rotatePages as dependantRotatePages } from '../shared-operations/functions/rotatePages.js'; +import { scaleContent as dependantScaleContent} from '../shared-operations/functions/scaleContent.js'; +import { scalePage as dependantScalePage } from '../shared-operations/functions/scalePage.js'; +import { splitPDF as dependantSplitPDF } from '../shared-operations/functions/splitPDF.js'; +import { editMetadata as dependantEditMetadata } from '../shared-operations/functions/editMetadata.js'; +import { organizePages as dependantOrganizePages } from '../shared-operations/functions/organizePages.js'; +import { removeBlankPages as dependantRemoveBlankPages} from '../shared-operations/functions/removeBlankPages.js'; +import { splitOn as dependantSplitOn } from "../shared-operations/functions/splitOn.js"; export async function extractPages(snapshot, pagesToExtractArray) { return dependantExtractPages(snapshot, pagesToExtractArray, PDFLib); diff --git a/routes/api/index.js b/server-node/routes/api/index.js similarity index 100% rename from routes/api/index.js rename to server-node/routes/api/index.js diff --git a/routes/api/workflow.js b/server-node/routes/api/workflow.js similarity index 96% rename from routes/api/workflow.js rename to server-node/routes/api/workflow.js index 43a931b2b..8e3fe270b 100644 --- a/routes/api/workflow.js +++ b/server-node/routes/api/workflow.js @@ -4,7 +4,7 @@ import stream from "stream"; import Archiver from 'archiver'; import * as Functions from "../../functions.js"; -import { traverseOperations } from "../../public/traverseOperations.js"; +import { traverseOperations } from "../../../shared-operations/traverseOperations.js"; const activeWorkflows = {}; @@ -17,7 +17,12 @@ router.post("/:workflowUuid?", [ return; } - req.files = Array.from(req.files.files); // Convert single values to array, keep arrays as is. + if(Array.isArray(req.files.files)) { + req.files = req.files.files; + } + else { + req.files = [req.files.files]; + } const workflow = JSON.parse(req.body.workflow); // TODO: Validate input further (json may fail or not be a valid workflow) diff --git a/public/functions/editMetadata.js b/shared-operations/functions/editMetadata.js similarity index 100% rename from public/functions/editMetadata.js rename to shared-operations/functions/editMetadata.js diff --git a/public/functions/extractPages.js b/shared-operations/functions/extractPages.js similarity index 100% rename from public/functions/extractPages.js rename to shared-operations/functions/extractPages.js diff --git a/public/functions/impose.js b/shared-operations/functions/impose.js similarity index 100% rename from public/functions/impose.js rename to shared-operations/functions/impose.js diff --git a/public/functions/mergePDFs.js b/shared-operations/functions/mergePDFs.js similarity index 100% rename from public/functions/mergePDFs.js rename to shared-operations/functions/mergePDFs.js diff --git a/public/functions/organizePages.js b/shared-operations/functions/organizePages.js similarity index 100% rename from public/functions/organizePages.js rename to shared-operations/functions/organizePages.js diff --git a/public/functions/removeBlankPages.js b/shared-operations/functions/removeBlankPages.js similarity index 100% rename from public/functions/removeBlankPages.js rename to shared-operations/functions/removeBlankPages.js diff --git a/public/functions/rotatePages.js b/shared-operations/functions/rotatePages.js similarity index 100% rename from public/functions/rotatePages.js rename to shared-operations/functions/rotatePages.js diff --git a/public/functions/scaleContent.js b/shared-operations/functions/scaleContent.js similarity index 100% rename from public/functions/scaleContent.js rename to shared-operations/functions/scaleContent.js diff --git a/public/functions/scalePage.js b/shared-operations/functions/scalePage.js similarity index 100% rename from public/functions/scalePage.js rename to shared-operations/functions/scalePage.js diff --git a/public/functions/shared/createSubDocument.js b/shared-operations/functions/shared/createSubDocument.js similarity index 100% rename from public/functions/shared/createSubDocument.js rename to shared-operations/functions/shared/createSubDocument.js diff --git a/public/functions/shared/detectEmptyPages.js b/shared-operations/functions/shared/detectEmptyPages.js similarity index 100% rename from public/functions/shared/detectEmptyPages.js rename to shared-operations/functions/shared/detectEmptyPages.js diff --git a/public/functions/shared/getImagesOnPage.js b/shared-operations/functions/shared/getImagesOnPage.js similarity index 100% rename from public/functions/shared/getImagesOnPage.js rename to shared-operations/functions/shared/getImagesOnPage.js diff --git a/public/functions/splitOn.js b/shared-operations/functions/splitOn.js similarity index 94% rename from public/functions/splitOn.js rename to shared-operations/functions/splitOn.js index 013c3f9b5..f4df4d061 100644 --- a/public/functions/splitOn.js +++ b/shared-operations/functions/splitOn.js @@ -75,10 +75,11 @@ export async function splitOn(snapshot, type, whiteThreashold, PDFJS, OpenCV, PD const pagesWithQR = []; for (let i = 0; i < pdfDoc.numPages; i++) { + console.log("Page:", i, "/", pdfDoc.numPages); const page = await pdfDoc.getPage(i + 1); const images = await getImagesOnPage(page, PDFJS); - + console.log("images:", images); for (const image of images) { const data = await checkForQROnImage(image); if(data == "https://github.com/Frooodle/Stirling-PDF") { @@ -86,12 +87,16 @@ export async function splitOn(snapshot, type, whiteThreashold, PDFJS, OpenCV, PD } } } + if(pagesWithQR.length == 0) { + console.warn("Could not find any QR Codes in the provided PDF.") + } return pagesWithQR; } async function checkForQROnImage(image) { // TODO: There is an issue with the jsQR package (The package expects rgba but sometimes we have rgb), and the package seems to be stale, we could create a fork and fix the issue. In the meanwhile we just force rgba: // Check for rgb and convert to rgba + if(image.data.length == image.width * image.height * 3) { const tmpArray = new Uint8ClampedArray(image.width * image.height * 4); diff --git a/public/functions/splitPDF.js b/shared-operations/functions/splitPDF.js similarity index 100% rename from public/functions/splitPDF.js rename to shared-operations/functions/splitPDF.js diff --git a/public/organizeWaitOperations.js b/shared-operations/organizeWaitOperations.js similarity index 100% rename from public/organizeWaitOperations.js rename to shared-operations/organizeWaitOperations.js diff --git a/public/traverseOperations.js b/shared-operations/traverseOperations.js similarity index 100% rename from public/traverseOperations.js rename to shared-operations/traverseOperations.js diff --git a/public/wasm/browserfs.min.js b/shared-operations/wasm/browserfs.min.js similarity index 100% rename from public/wasm/browserfs.min.js rename to shared-operations/wasm/browserfs.min.js diff --git a/public/wasm/opencv/opencv_3_4_custom_O3.js b/shared-operations/wasm/opencv/opencv_3_4_custom_O3.js similarity index 100% rename from public/wasm/opencv/opencv_3_4_custom_O3.js rename to shared-operations/wasm/opencv/opencv_3_4_custom_O3.js diff --git a/public/wasm/pdfcpu-wrapper-browser.js b/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js similarity index 94% rename from public/wasm/pdfcpu-wrapper-browser.js rename to shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js index b0cbad7cf..73cffdf4b 100644 --- a/public/wasm/pdfcpu-wrapper-browser.js +++ b/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-browser.js @@ -1,10 +1,11 @@ -// TODO: Uses the BrowserFS import, needs to be changed for serverside +// imports browserfs via index.html script-tag -let wasmLocation = "/wasm/"; +let wasmLocation = "/wasm/pdfcpu/"; let fs; let Buffer; +// TODO: This can later be defered to load asynchronously configureFs(); loadWasm(); diff --git a/public/wasm/pdfcpu-wrapper-node.js b/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-node.js similarity index 98% rename from public/wasm/pdfcpu-wrapper-node.js rename to shared-operations/wasm/pdfcpu/pdfcpu-wrapper-node.js index 9e64c9e68..6ce3a2e95 100644 --- a/public/wasm/pdfcpu-wrapper-node.js +++ b/shared-operations/wasm/pdfcpu/pdfcpu-wrapper-node.js @@ -1,5 +1,3 @@ -// TODO: Uses the BrowserFS import, needs to be changed for serverside - import { WasmFs } from '@wasmer/wasmfs'; import path from "path"; @@ -9,6 +7,7 @@ let nodeWasmLocation = "./public/wasm/"; let fs; const wasmfs = new WasmFs(); +// TODO: This can later be defered to load asynchronously (async () => { await loadWasm(); await configureFs(); diff --git a/public/wasm/pdfcpu.wasm b/shared-operations/wasm/pdfcpu/pdfcpu.wasm similarity index 100% rename from public/wasm/pdfcpu.wasm rename to shared-operations/wasm/pdfcpu/pdfcpu.wasm diff --git a/public/wasm/wasm_exec.js b/shared-operations/wasm/pdfcpu/wasm_exec.js similarity index 100% rename from public/wasm/wasm_exec.js rename to shared-operations/wasm/pdfcpu/wasm_exec.js