added endpoint: extract-pages. changed indecies to indexes

This commit is contained in:
Saud Fatayerji 2023-11-19 11:38:55 +03:00
parent facf1553ec
commit a7545b017f
4 changed files with 14 additions and 9 deletions

View File

@ -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

View File

@ -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 {

View File

@ -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<PdfFile> {
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;
}

View File

@ -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;