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 //Auto Split Pages
//Adjust Colours/Contrast //Adjust Colours/Contrast
//Crop //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 //PDF to Single large Page

View File

@ -9,7 +9,7 @@ export interface WaitAction extends Action {
} }
export interface ExtractAction extends Action { export interface ExtractAction extends Action {
values: { indecies: string | number[] } values: { indexes: string | number[] }
} }
export interface ImposeAction extends Action { export interface ImposeAction extends Action {

View File

@ -5,19 +5,19 @@ import { parsePageIndexSpecification } from './common/pageIndexesUtils'
export type ExtractPagesParamsType = { export type ExtractPagesParamsType = {
file: PdfFile; file: PdfFile;
pageIndecies: string | number[]; pageIndexes: string | number[];
} }
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> { export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
const { file, pageIndecies: pageIndecies } = params; const { file, pageIndexes } = params;
const pdfLibDocument = await file.pdfLibDocument; const pdfLibDocument = await file.pdfLibDocument;
var indecies = pageIndecies; var indexes = pageIndexes;
if (!Array.isArray(indecies)) { if (!Array.isArray(indexes)) {
indecies = parsePageIndexSpecification(indecies, pdfLibDocument.getPageCount()); indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
} }
const newFile = await getPages(file, indecies); const newFile = await getPages(file, indexes);
newFile.filename += "_extractedPages" newFile.filename += "_extractedPages"
return newFile; return newFile;
} }

View File

@ -54,7 +54,7 @@ export async function * traverseOperations(operations: Action[], input: PdfFile[
break; break;
case "extract": case "extract":
yield* nToN(input, action, async (input) => { 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; return newPdf;
}); });
break; break;