UNPKG

express-image-validator

Version:

Validator of various image parameters in Express.js applications

24 lines (23 loc) 914 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.validateSize = void 0; const size_1 = require("./errors/size"); /** * Validates that the uploaded file's size is within the specified `minSize` and `maxSize` limits. * @type { FileValidatorFunction } * @param { string } field Field name. * @param { UploadedFile } file The uploaded file. * @param { ValidationOptions } options Validation options containing `minSize` and `maxSize`. * @returns { ValidationResult } */ const validateSize = (field, file, { minSize, maxSize }) => { const errors = []; if (file.size < minSize) { errors.push((0, size_1.tooLightError)(field, minSize, file.name, file.size)); } if (maxSize && file.size > maxSize) { errors.push((0, size_1.tooLargeError)(field, maxSize, file.name, file.size)); } return { errors }; }; exports.validateSize = validateSize;