mirror of
https://github.com/Frooodle/Stirling-PDF.git
synced 2025-01-23 00:06:08 +01:00
Fixed yields for functions
This commit is contained in:
parent
0bf8c520aa
commit
2bc618d66b
@ -5,7 +5,7 @@ import { rotatePages } from "./functions/rotatePDF.js";
|
|||||||
import { splitPDF } from "./functions/splitPDF.js";
|
import { splitPDF } from "./functions/splitPDF.js";
|
||||||
import { organizeWaitOperations } from "./organizeWaitOperations.js";
|
import { organizeWaitOperations } from "./organizeWaitOperations.js";
|
||||||
|
|
||||||
// TODO: Make this run with feedback like the server side func.
|
// TODO: Make this run with feedback like the server side func & The serverside func also got now functionality & fixes for split, so copy it and make it work with the new readsteam system on frontend
|
||||||
export async function traverseOperations(operations, input) {
|
export async function traverseOperations(operations, input) {
|
||||||
const waitOperations = organizeWaitOperations(operations);
|
const waitOperations = organizeWaitOperations(operations);
|
||||||
const results = [];
|
const results = [];
|
||||||
|
@ -45,11 +45,11 @@ router.post("/:workflowUuid?", [
|
|||||||
while (true) {
|
while (true) {
|
||||||
iteration = await traverse.next();
|
iteration = await traverse.next();
|
||||||
if (iteration.done) {
|
if (iteration.done) {
|
||||||
console.log(iteration.value);
|
|
||||||
pdfResults = iteration.value;
|
pdfResults = iteration.value;
|
||||||
console.log("Done");
|
console.log("Done");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
console.log(iteration.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Download");
|
console.log("Download");
|
||||||
|
@ -15,6 +15,7 @@ export async function * traverseOperations(operations, input) {
|
|||||||
|
|
||||||
// TODO: Pult all nextOperation() in the for await, like for "extract"
|
// TODO: Pult all nextOperation() in the for await, like for "extract"
|
||||||
async function * nextOperation(operations, input) {
|
async function * nextOperation(operations, input) {
|
||||||
|
console.log(Array.isArray(operations) && operations.length == 0);
|
||||||
if(Array.isArray(operations) && operations.length == 0) { // isEmpty
|
if(Array.isArray(operations) && operations.length == 0) { // isEmpty
|
||||||
if(Array.isArray(input)) {
|
if(Array.isArray(input)) {
|
||||||
console.log("operation done: " + input[0].fileName + "+");
|
console.log("operation done: " + input[0].fileName + "+");
|
||||||
@ -36,6 +37,7 @@ export async function * traverseOperations(operations, input) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function * computeOperation(operation, input) {
|
async function * computeOperation(operation, input) {
|
||||||
|
yield "Starting: " + operation.type;
|
||||||
switch (operation.type) {
|
switch (operation.type) {
|
||||||
case "done":
|
case "done":
|
||||||
console.log("Done operation will get called if all waits are done. Skipping for now.")
|
console.log("Done operation will get called if all waits are done. Skipping for now.")
|
||||||
@ -59,7 +61,9 @@ export async function * traverseOperations(operations, input) {
|
|||||||
|
|
||||||
waitOperation.waitCount--;
|
waitOperation.waitCount--;
|
||||||
if(waitOperation.waitCount == 0) {
|
if(waitOperation.waitCount == 0) {
|
||||||
await nextOperation(waitOperation.doneOperation.operations, waitOperation.input);
|
for await (const value of nextOperation(waitOperation.doneOperation.operations, waitOperation.input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "removeObjects":
|
case "removeObjects":
|
||||||
@ -69,13 +73,17 @@ export async function * traverseOperations(operations, input) {
|
|||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input[i].fileName += "_removedObjects";
|
input[i].fileName += "_removedObjects";
|
||||||
await nextOperation(operation.operations, input[i]);
|
for await (const value of nextOperation(operation.operations, input[i])) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input.fileName += "_removedObjects";
|
input.fileName += "_removedObjects";
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "extract":
|
case "extract":
|
||||||
@ -111,7 +119,6 @@ export async function * traverseOperations(operations, input) {
|
|||||||
splitCount: splitResult.length
|
splitCount: splitResult.length
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
console.log(splits);
|
|
||||||
|
|
||||||
for await (const value of nextOperation(operation.operations, splits)) {
|
for await (const value of nextOperation(operation.operations, splits)) {
|
||||||
yield value;
|
yield value;
|
||||||
@ -143,13 +150,17 @@ export async function * traverseOperations(operations, input) {
|
|||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input[i].fileName += "_filledField";
|
input[i].fileName += "_filledField";
|
||||||
await nextOperation(operation.operations, input[i]);
|
for await (const value of nextOperation(operation.operations, input[i])) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input.fileName += "_filledField";
|
input.fileName += "_filledField";
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "extractImages":
|
case "extractImages":
|
||||||
@ -159,13 +170,17 @@ export async function * traverseOperations(operations, input) {
|
|||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input[i].fileName += "_extractedImages";
|
input[i].fileName += "_extractedImages";
|
||||||
await nextOperation(operation.operations, input[i]);
|
for await (const value of nextOperation(operation.operations, input[i])) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input.fileName += "_extractedImages";
|
input.fileName += "_extractedImages";
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "merge":
|
case "merge":
|
||||||
@ -181,7 +196,9 @@ export async function * traverseOperations(operations, input) {
|
|||||||
// Only one input, no need to merge
|
// Only one input, no need to merge
|
||||||
input.fileName += "_merged";
|
input.fileName += "_merged";
|
||||||
}
|
}
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case "transform": {
|
case "transform": {
|
||||||
console.warn("Transform not implemented yet.")
|
console.warn("Transform not implemented yet.")
|
||||||
@ -189,13 +206,17 @@ export async function * traverseOperations(operations, input) {
|
|||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input[i].fileName += "_transformed";
|
input[i].fileName += "_transformed";
|
||||||
await nextOperation(operation.operations, input[i]);
|
for await (const value of nextOperation(operation.operations, input[i])) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// TODO: modfiy input
|
// TODO: modfiy input
|
||||||
input.fileName += "_transformed";
|
input.fileName += "_transformed";
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -204,13 +225,17 @@ export async function * traverseOperations(operations, input) {
|
|||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
input[i].fileName += "_extractedPages";
|
input[i].fileName += "_extractedPages";
|
||||||
input[i].buffer = await extractPages(input[i].buffer, operation.values["pagesToExtractArray"]);
|
input[i].buffer = await extractPages(input[i].buffer, operation.values["pagesToExtractArray"]);
|
||||||
await nextOperation(operation.operations, input[i]);
|
for await (const value of nextOperation(operation.operations, input[i])) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
input.fileName += "_extractedPages";
|
input.fileName += "_extractedPages";
|
||||||
input.buffer = await extractPages(input.buffer, operation.values["pagesToExtractArray"]);
|
input.buffer = await extractPages(input.buffer, operation.values["pagesToExtractArray"]);
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "rotate":
|
case "rotate":
|
||||||
@ -218,13 +243,17 @@ export async function * traverseOperations(operations, input) {
|
|||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
input[i].fileName += "_turned";
|
input[i].fileName += "_turned";
|
||||||
input[i].buffer = await rotatePages(input[i].buffer, operation.values["rotation"]);
|
input[i].buffer = await rotatePages(input[i].buffer, operation.values["rotation"]);
|
||||||
await nextOperation(operation.operations, input[i]);
|
for await (const value of nextOperation(operation.operations, input[i])) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
input.fileName += "_turned";
|
input.fileName += "_turned";
|
||||||
input.buffer = await rotatePages(input.buffer, operation.values["rotation"]);
|
input.buffer = await rotatePages(input.buffer, operation.values["rotation"]);
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "impose":
|
case "impose":
|
||||||
@ -232,19 +261,22 @@ export async function * traverseOperations(operations, input) {
|
|||||||
for (let i = 0; i < input.length; i++) {
|
for (let i = 0; i < input.length; i++) {
|
||||||
input[i].fileName += "_imposed";
|
input[i].fileName += "_imposed";
|
||||||
input[i].buffer = await impose(input[i].buffer, operation.values["nup"], operation.values["format"]);
|
input[i].buffer = await impose(input[i].buffer, operation.values["nup"], operation.values["format"]);
|
||||||
await nextOperation(operation.operations, input[i]);
|
for await (const value of nextOperation(operation.operations, input[i])) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
input.fileName += "_imposed";
|
input.fileName += "_imposed";
|
||||||
input.buffer = await impose(input.buffer, operation.values["nup"], operation.values["format"]);
|
input.buffer = await impose(input.buffer, operation.values["nup"], operation.values["format"]);
|
||||||
await nextOperation(operation.operations, input);
|
for await (const value of nextOperation(operation.operations, input)) {
|
||||||
|
yield value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
console.log("operation type unknown: ", operation.type);
|
console.log("operation type unknown: ", operation.type);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
yield operation.type;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user