Staging #1066
3 changed files with 36 additions and 13 deletions
|
@ -33,7 +33,10 @@
|
|||
"approvedChannels": [],
|
||||
"publishingChannelWhitelist": [],
|
||||
"channelClaimBidAmount": "0.1",
|
||||
"fileClaimBidAmount": "0.01"
|
||||
"fileClaimBidAmount": "0.01",
|
||||
"maxSizeImage": 10000000,
|
||||
"maxSizeGif": 50000000,
|
||||
"maxSizeVideo": 50000000
|
||||
},
|
||||
"startup": {
|
||||
"performChecks": true,
|
||||
|
|
|
@ -1,3 +1,13 @@
|
|||
import siteConfig from '@config/siteConfig.json';
|
||||
|
||||
const {
|
||||
publishing: {
|
||||
maxSizeImage = 10000000,
|
||||
maxSizeGif = 50000000,
|
||||
maxSizeVideo = 50000000,
|
||||
}
|
||||
} = siteConfig;
|
||||
|
||||
module.exports = {
|
||||
validateFile (file) {
|
||||
if (!file) {
|
||||
|
@ -11,18 +21,18 @@ module.exports = {
|
|||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
case 'image/png':
|
||||
if (file.size > 10000000) {
|
||||
throw new Error('Sorry, images are limited to 10 megabytes.');
|
||||
if (file.size > maxSizeImage) {
|
||||
throw new Error(`Sorry, images are limited to ${maxSizeImage / SIZE_MB} megabytes.`);
|
||||
}
|
||||
break;
|
||||
case 'image/gif':
|
||||
if (file.size > 50000000) {
|
||||
throw new Error('Sorry, GIFs are limited to 50 megabytes.');
|
||||
if (file.size > maxSizeGif) {
|
||||
throw new Error(`Sorry, .gifs are limited to ${maxSizeGif / SIZE_MB} megabytes.`);
|
||||
}
|
||||
break;
|
||||
case 'video/mp4':
|
||||
if (file.size > 50000000) {
|
||||
throw new Error('Sorry, videos are limited to 50 megabytes.');
|
||||
if (file.size > maxSizeVideo) {
|
||||
throw new Error(`Sorry, videos are limited to ${maxSizeVideo / SIZE_MB} megabytes.`);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -1,26 +1,36 @@
|
|||
const logger = require('winston');
|
||||
|
||||
const {
|
||||
publishing: {
|
||||
maxSizeImage = 10000000,
|
||||
maxSizeGif = 50000000,
|
||||
maxSizeVideo = 50000000,
|
||||
}
|
||||
} = require('@config/siteConfig');
|
||||
|
||||
const SIZE_MB = 1000000;
|
||||
|
||||
const validateFileTypeAndSize = (file) => {
|
||||
// check file type and size
|
||||
switch (file.type) {
|
||||
case 'image/jpeg':
|
||||
case 'image/jpg':
|
||||
case 'image/png':
|
||||
if (file.size > 10000000) {
|
||||
if (file.size > maxSizeImage) {
|
||||
logger.debug('publish > file validation > .jpeg/.jpg/.png was too big');
|
||||
throw new Error('Sorry, images are limited to 10 megabytes.');
|
||||
throw new Error(`Sorry, images are limited to ${maxSizeImage / SIZE_MB} megabytes.`);
|
||||
}
|
||||
break;
|
||||
case 'image/gif':
|
||||
if (file.size > 50000000) {
|
||||
if (file.size > maxSizeGif) {
|
||||
logger.debug('publish > file validation > .gif was too big');
|
||||
throw new Error('Sorry, .gifs are limited to 50 megabytes.');
|
||||
throw new Error(`Sorry, .gifs are limited to ${maxSizeGif / SIZE_MB} megabytes.`);
|
||||
}
|
||||
break;
|
||||
case 'video/mp4':
|
||||
if (file.size > 50000000) {
|
||||
if (file.size > maxSizeVideo) {
|
||||
logger.debug('publish > file validation > .mp4 was too big');
|
||||
throw new Error('Sorry, videos are limited to 50 megabytes.');
|
||||
throw new Error(`Sorry, videos are limited to ${maxSizeVideo / SIZE_MB} megabytes.`);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
|
Loading…
Reference in a new issue