Merge pull request #766 from lbryio/addUploadLimitConfig

Add upload limit configurations
This commit is contained in:
Shawn K 2018-11-27 23:28:24 -06:00 committed by GitHub
commit e67e4d3ad2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 36 additions and 13 deletions

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: