Skip to content

Commit

Permalink
Merge pull request #70 from italia/file-validator
Browse files Browse the repository at this point in the history
File extensions validator
  • Loading branch information
libremente authored Jun 3, 2019
2 parents dca0f80 + 82d63e4 commit e205585
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/app/contents/fields/generic.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,17 @@ const fields = async () => {
label: "Logo",
description:
"This key contains the logo of the software. Logos should be in vector format; raster formats are only allowed as a fallback. In this case, they should be transparent PNGs, minimum 1000px of width. Acceptable formats: SVG, SVGZ, PNG",
section: 2
section: 2,
fileExt: ['svg','svgz','png']
},
{
type: "string",
title: "monochromeLogo",
label: "Logo Monochrome",
description:
"A monochromatic (black) logo. The logo should be in vector format; raster formats are only allowed as a fallback. In this case, they should be transparent PNGs, minimum 1000px of width. Acceptable formats: SVG, SVGZ, PNG",
section: 2
section: 2,
fileExt: ['svg','svgz','png']
},
{
title: "developmentStatus",
Expand Down
9 changes: 9 additions & 0 deletions src/app/utils/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ export const checkField = (field, obj, value, required) => {
if (_.has(obj, 'maxLength') && !validator.isLength(strip(value).trim(), {min: undefined, max: obj.maxLength}))
return "Not a valid input maximum length.";

if (_.has(obj, 'fileExt') && Array.isArray(obj.fileExt)) {
let extMatch = 0;
obj.fileExt.forEach(ext => {
if(value.toLowerCase().split('.').pop() == ext.toLowerCase())
extMatch++;
});
if (extMatch == 0)
return `Not a valid extension, allowed only: ${obj.fileExt}`;
}

if (obj && obj.widget) {
let widget = obj.widget;
Expand Down

0 comments on commit e205585

Please # to comment.