Staging #1066

Merged
jessopb merged 55 commits from staging into release 2020-05-16 17:08:51 +02:00
3 changed files with 36 additions and 13 deletions
Showing only changes of commit 40a8c04daa - Show all commits

View file

@ -33,7 +33,10 @@
"approvedChannels": [],
"publishingChannelWhitelist": [],
"channelClaimBidAmount": "0.1",
"fileClaimBidAmount": "0.01"
"fileClaimBidAmount": "0.01",
"maxSizeImage": 10000000,
"maxSizeGif": 50000000,
"maxSizeVideo": 50000000
},
"startup": {
"performChecks": true,

View file

@ -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:

View file

@ -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: