From a7545b017f959e3422a6d6a684b052aafe6fc1a3 Mon Sep 17 00:00:00 2001 From: Saud Fatayerji Date: Sun, 19 Nov 2023 11:38:55 +0300 Subject: [PATCH] added endpoint: extract-pages. changed indecies to indexes --- server-node/src/routes/api/operations-controller.ts | 7 ++++++- shared-operations/declarations/Action.d.ts | 2 +- shared-operations/src/functions/extractPages.ts | 12 ++++++------ shared-operations/src/workflow/traverseOperations.ts | 2 +- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/server-node/src/routes/api/operations-controller.ts b/server-node/src/routes/api/operations-controller.ts index 02c885b5..1538babd 100644 --- a/server-node/src/routes/api/operations-controller.ts +++ b/server-node/src/routes/api/operations-controller.ts @@ -90,7 +90,12 @@ registerEndpoint("/scale-pages", "", upload.single("file"), Operations.scalePage //Auto Split Pages //Adjust Colours/Contrast //Crop -//Extract Pages + +registerEndpoint("/extract-pages", "", upload.single("file"), Operations.extractPages, Joi.object({ + file: PdfFileSchema.required(), + pageIndexes: Joi.alternatives().try(Joi.string(), Joi.array().items(Joi.number())).required(), +}).required()); + //PDF to Single large Page diff --git a/shared-operations/declarations/Action.d.ts b/shared-operations/declarations/Action.d.ts index 2019e33d..d2d4ec1b 100644 --- a/shared-operations/declarations/Action.d.ts +++ b/shared-operations/declarations/Action.d.ts @@ -9,7 +9,7 @@ export interface WaitAction extends Action { } export interface ExtractAction extends Action { - values: { indecies: string | number[] } + values: { indexes: string | number[] } } export interface ImposeAction extends Action { diff --git a/shared-operations/src/functions/extractPages.ts b/shared-operations/src/functions/extractPages.ts index 46b69843..c1206f96 100644 --- a/shared-operations/src/functions/extractPages.ts +++ b/shared-operations/src/functions/extractPages.ts @@ -5,19 +5,19 @@ import { parsePageIndexSpecification } from './common/pageIndexesUtils' export type ExtractPagesParamsType = { file: PdfFile; - pageIndecies: string | number[]; + pageIndexes: string | number[]; } export async function extractPages(params: ExtractPagesParamsType): Promise { - const { file, pageIndecies: pageIndecies } = params; + const { file, pageIndexes } = params; const pdfLibDocument = await file.pdfLibDocument; - var indecies = pageIndecies; + var indexes = pageIndexes; - if (!Array.isArray(indecies)) { - indecies = parsePageIndexSpecification(indecies, pdfLibDocument.getPageCount()); + if (!Array.isArray(indexes)) { + indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount()); } - const newFile = await getPages(file, indecies); + const newFile = await getPages(file, indexes); newFile.filename += "_extractedPages" return newFile; } diff --git a/shared-operations/src/workflow/traverseOperations.ts b/shared-operations/src/workflow/traverseOperations.ts index 7f3e18d3..5e7f579a 100644 --- a/shared-operations/src/workflow/traverseOperations.ts +++ b/shared-operations/src/workflow/traverseOperations.ts @@ -54,7 +54,7 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[ break; case "extract": yield* nToN(input, action, async (input) => { - const newPdf = await Operations.extractPages({file: input, pageIndecies: action.values["pageIndecies"]}); + const newPdf = await Operations.extractPages({file: input, pageIndexes: action.values["pageIndexes"]}); return newPdf; }); break;