extract, comma seperated list fields in Joi & genericField
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
|
||||
import { PdfFile, RepresentationType } from "../wrappers/PdfFile";
|
||||
import { Operator, Progress, oneToOne } from ".";
|
||||
|
||||
@@ -9,26 +8,7 @@ import i18next from "i18next";
|
||||
|
||||
import { getPages } from "./common/getPagesByIndex";
|
||||
import { parsePageIndexSpecification } from "./common/pageIndexesUtils";
|
||||
|
||||
export interface ExtractPagesParamsType {
|
||||
file: PdfFile;
|
||||
pageIndexes: string | number[];
|
||||
}
|
||||
export async function extractPages(params: ExtractPagesParamsType): Promise<PdfFile> {
|
||||
const { file, pageIndexes } = params;
|
||||
const pdfLibDocument = await file.pdfLibDocument;
|
||||
|
||||
let indexes = pageIndexes;
|
||||
|
||||
if (!Array.isArray(indexes)) {
|
||||
indexes = parsePageIndexSpecification(indexes, pdfLibDocument.getPageCount());
|
||||
}
|
||||
|
||||
const newFile = await getPages(file, indexes);
|
||||
newFile.filename += "_extractedPages";
|
||||
return newFile;
|
||||
}
|
||||
|
||||
import CommaArrayJoiExt from "../wrappers/CommaArrayJoiExt";
|
||||
|
||||
export class ExtractPages extends Operator {
|
||||
static type = "extractPages";
|
||||
@@ -39,9 +19,9 @@ export class ExtractPages extends Operator {
|
||||
|
||||
protected static inputSchema = JoiPDFFileSchema.label(i18next.t("inputs.pdffile.name")).description(i18next.t("inputs.pdffile.description"));
|
||||
protected static valueSchema = Joi.object({
|
||||
pageIndexes: Joi.array().items(Joi.number().integer()).required()
|
||||
pageIndexes: CommaArrayJoiExt.comma_array().items(Joi.number().integer()).required()
|
||||
.label(i18next.t("values.pageIndexes.friendlyName", { ns: "extractPages" })).description(i18next.t("values.pageIndexes.description", { ns: "extractPages" }))
|
||||
.example("3").example("4").required()
|
||||
.example("1").example("1, 2, 3, 4").example("4, 2, 4, 3").required()
|
||||
});
|
||||
protected static outputSchema = JoiPDFFileSchema.label(i18next.t("outputs.pdffile.name")).description(i18next.t("outputs.pdffile.description"));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user