refactor: pull all base fields out of collection sanitize

This commit is contained in:
Elliot DeNolf
2020-11-17 14:39:10 -05:00
parent 1de5ac8cba
commit fe536f0628
6 changed files with 120 additions and 1 deletions

View File

@@ -1,4 +1,4 @@
const validations = require('../fields/validations');
const validations = require('../validations');
module.exports = [
{

View File

@@ -0,0 +1,78 @@
module.exports = (imageSizes) => [
{
name: 'width',
label: 'Width',
type: 'number',
admin: {
readOnly: true,
disabled: true,
},
}, {
name: 'height',
label: 'Height',
type: 'number',
admin: {
readOnly: true,
disabled: true,
},
},
{
name: 'sizes',
label: 'Sizes',
type: 'group',
admin: {
disabled: true,
},
fields: imageSizes.map((size) => ({
label: size.name,
name: size.name,
type: 'group',
admin: {
disabled: true,
},
fields: [
{
name: 'width',
label: 'Width',
type: 'number',
admin: {
readOnly: true,
disabled: true,
},
}, {
name: 'height',
label: 'Height',
type: 'number',
admin: {
readOnly: true,
disabled: true,
},
}, {
name: 'mimeType',
label: 'MIME Type',
type: 'text',
admin: {
readOnly: true,
disabled: true,
},
}, {
name: 'filesize',
label: 'File Size',
type: 'number',
admin: {
readOnly: true,
disabled: true,
},
}, {
name: 'filename',
label: 'File Name',
type: 'text',
admin: {
readOnly: true,
disabled: true,
},
},
],
})),
},
];

View File

@@ -0,0 +1,41 @@
module.exports = [
{
name: 'filename',
label: 'Filename',
hooks: {
beforeChange: [
({ req, operation, value }) => {
if (operation === 'create') {
const file = (req.files && req.files.file) ? req.files.file : req.file;
return file.name;
}
return value;
},
],
},
type: 'text',
required: true,
unique: true,
admin: {
disabled: true,
readOnly: true,
},
}, {
name: 'mimeType',
label: 'MIME Type',
type: 'text',
admin: {
readOnly: true,
disabled: true,
},
}, {
name: 'filesize',
label: 'File Size',
type: 'number',
admin: {
readOnly: true,
disabled: true,
},
},
];