mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-04-19 19:21:18 +00:00
restructured project (shared-operations)
This commit is contained in:
parent
7186c6c3e0
commit
47e0092378
@ -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);
|
||||
}
|
@ -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(/\.[^/.]+$/, ""),
|
5
index.js
5
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');
|
||||
|
@ -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);
|
@ -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)
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -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();
|
Loading…
x
Reference in New Issue
Block a user