custom validator express validator
body("thumbnail_file").custom(async (value, { req }) => {
const thumbnailFile = req.files && req.files.thumbnail_file;
if (!thumbnailFile) {
return true;
} else if (Array.isArray(thumbnailFile)) {
throw new Error("Only one thumbnail file is allowed.");
}
if (
thumbnailFile.mimetype !== "image/png" &&
thumbnailFile.mimetype !== "image/jpg" &&
thumbnailFile.mimetype !== "image/jpeg"
) {
throw new Error(
"Only .png, .jpg and .jpeg image formats are allowed for thumbnail file."
);
}
}),