diff --git a/shared-operations/src/functions/extractPages.ts b/shared-operations/src/functions/extractPages.ts index eeeadbbb..1b6b9bbc 100644 --- a/shared-operations/src/functions/extractPages.ts +++ b/shared-operations/src/functions/extractPages.ts @@ -6,7 +6,7 @@ export type ExtractPagesParamsType = { file: PdfFile; pageIndexes: string | number[]; } -export async function extractPages(params: ExtractPagesParamsType) { +export async function extractPages(params: ExtractPagesParamsType): Promise { const { file, pageIndexes } = params; const pdfLibDocument = await file.pdfLibDocument; @@ -16,5 +16,7 @@ export async function extractPages(params: ExtractPagesParamsType) { indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount()); } - return getPages(file, indexes); + const newFile = await getPages(file, indexes); + newFile.filename += "_extractedPages" + return newFile; } diff --git a/shared-operations/src/functions/removeBlankPages.ts b/shared-operations/src/functions/removeBlankPages.ts index d8242769..42525c25 100644 --- a/shared-operations/src/functions/removeBlankPages.ts +++ b/shared-operations/src/functions/removeBlankPages.ts @@ -14,5 +14,8 @@ export async function removeBlankPages(params: RemoveBlankPagesParamsType) { const emptyPages = await detectEmptyPages(file, whiteThreashold); console.debug("Empty Pages: ", emptyPages); const pagesToKeep = invertSelection(emptyPages, pageCount.getPageCount()) - return getPages(file, pagesToKeep); + + const newFile = await getPages(file, pagesToKeep); + newFile.filename += "_removedBlanks" + return newFile; } \ No newline at end of file diff --git a/shared-operations/src/functions/sortPagesWithPreset.ts b/shared-operations/src/functions/sortPagesWithPreset.ts index d32ac943..accf25ff 100644 --- a/shared-operations/src/functions/sortPagesWithPreset.ts +++ b/shared-operations/src/functions/sortPagesWithPreset.ts @@ -18,5 +18,8 @@ export async function sortPagesWithPreset(params: SortPagesWithPresetParamsType) const sortFunction = sorts[sortPreset]; const pageCount = pdfLibDocument.getPageCount(); const sortIndexes = sortFunction(pageCount); - return getPages(file, sortIndexes); + + const newFile = await getPages(file, sortIndexes); + newFile.filename += "_sortedPages" + return newFile; } diff --git a/shared-operations/src/workflow/traverseOperations.ts b/shared-operations/src/workflow/traverseOperations.ts index 612e7118..8394f32f 100644 --- a/shared-operations/src/workflow/traverseOperations.ts +++ b/shared-operations/src/workflow/traverseOperations.ts @@ -55,7 +55,6 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[ case "extract": yield* nToN(input, action, async (input) => { const newPdf = await Operations.extractPages({file: input, pageIndexes: action.values["pageIndexes"]}); - newPdf.filename += "_extractedPages"; return newPdf; }); break; @@ -71,12 +70,24 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[ return newPdf; }); break; + case "removeBlankPages": + yield* nToN(input, action, async (input) => { + const newPdf = await Operations.removeBlankPages({file: input, whiteThreashold: action.values["whiteThreashold"]}); + return newPdf; + }); + break; case "rotate": yield* nToN(input, action, async (input) => { const newPdf = await Operations.rotatePages({file: input, rotation: action.values["rotation"]}); return newPdf; }); break; + case "sortPagesWithPreset": + yield* nToN(input, action, async (input) => { + const newPdf = await Operations.sortPagesWithPreset({file: input, sortPreset: action.values["sortPreset"]}); + return newPdf; + }); + break; case "split": // TODO: A split might break the done condition, it may count multiple times. Needs further testing! yield* oneToN(input, action, async (input) => { @@ -87,27 +98,6 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[ return splitResult; }); break; - case "updateMetadata": - yield* nToN(input, action, async (input) => { - const newPdf = await Operations.updateMetadata({file: input, ...action.values["metadata"]}); - newPdf.filename += "_metadataEdited"; - return newPdf; - }); - break; - case "sortPagesWithPreset": - yield* nToN(input, action, async (input) => { - const newPdf = await Operations.sortPagesWithPreset({file: input, sortPreset: action.values["sortPreset"]}); - newPdf.filename += "_pagesOrganized"; - return newPdf; - }); - break; - case "removeBlankPages": - yield* nToN(input, action, async (input) => { - const newPdf = await Operations.removeBlankPages({file: input, whiteThreashold: action.values["whiteThreashold"]}); - newPdf.filename += "_removedBlanks"; - return newPdf; - }); - break; case "splitOn": yield* oneToN(input, action, async (input) => { const splitResult = await Operations.splitOn({file: input, type: action.values["type"], whiteThreashold: action.values["whiteThreashold"]}); @@ -117,9 +107,14 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[ return splitResult; }); break; + case "updateMetadata": + yield* nToN(input, action, async (input) => { + const newPdf = await Operations.updateMetadata({file: input, ...action.values["metadata"]}); + return newPdf; + }); + break; default: throw new Error(`${action.type} not implemented yet.`); - break; } }