Workflow and API validation for input file types
(still needs to be ckecked if a pdf is valid)
This commit is contained in:
@@ -1,8 +1,17 @@
|
||||
import Joi from "joi";
|
||||
import { PdfFile } from "./PdfFile";
|
||||
|
||||
export const JoiPDFFileSchema = Joi.binary().custom((value: Express.Multer.File[] | PdfFile, helpers) => {
|
||||
if (!(value instanceof PdfFile)) {
|
||||
export const JoiPDFFileSchema = Joi.binary().custom((value: Express.Multer.File[] | PdfFile | PdfFile[], helpers) => {
|
||||
if (value instanceof PdfFile) {
|
||||
return value;
|
||||
}
|
||||
else if (Array.isArray(value)) {
|
||||
if(value.every((e) => e instanceof PdfFile))
|
||||
return value;
|
||||
else
|
||||
throw new Error("Some elements in the array are not of type PdfFile");
|
||||
}
|
||||
else {
|
||||
try {
|
||||
return PdfFile.fromMulterFiles(value);
|
||||
} catch (error) {
|
||||
@@ -10,5 +19,4 @@ export const JoiPDFFileSchema = Joi.binary().custom((value: Express.Multer.File[
|
||||
throw new Error('value is not of type PdfFile');
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}, "pdffile validation");
|
||||
Reference in New Issue
Block a user