Refactor publish and validation and servability for all file types #902

Merged
jessopb merged 2 commits from refactorPublishValidate into master 2019-02-09 21:41:07 +01:00
2 changed files with 87 additions and 1 deletions
Showing only changes of commit 815d0437ac - Show all commits

View file

@ -23,7 +23,7 @@
"publishing": { "publishing": {
"primaryClaimAddress": null, "primaryClaimAddress": null,
"uploadDirectory": "/home/lbry/Uploads", "uploadDirectory": "/home/lbry/Uploads",
"lbrynetHome": "/home/lbry", "lbrynetHome": "/CURRENTLYUNUSED",
"thumbnailChannel": null, "thumbnailChannel": null,
"thumbnailChannelId": null, "thumbnailChannelId": null,
"additionalClaimAddresses": [], "additionalClaimAddresses": [],
@ -36,6 +36,17 @@
"publishingChannelWhitelist": [], "publishingChannelWhitelist": [],
"channelClaimBidAmount": "0.1", "channelClaimBidAmount": "0.1",
"fileClaimBidAmount": "0.01", "fileClaimBidAmount": "0.01",
"fileSizeLimits": {
"image": 50000000,
"video": 50000000,
"audio": 50000000,
"text": 50000000,
"model": 50000000,
"application": 50000000,
"customByContentType": {
"application/octet-stream": 50000000
}
},
"maxSizeImage": 10000000, "maxSizeImage": 10000000,
"maxSizeGif": 50000000, "maxSizeGif": 50000000,
"maxSizeVideo": 50000000 "maxSizeVideo": 50000000

View file

@ -0,0 +1,75 @@
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
import { publishing } from '@config/siteConfig.json';
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
const {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
fileSizeLimits: {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
image: maxSizeImage = 10000000,
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
video: maxSizeVideo = 50000000,
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
audio: maxSizeAudio = 50000000,
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
text: maxSizeText = 50000000,
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
model: maxSizeModel = 50000000,
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
application: maxSizeApplication = 50000000,
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
customByContentType,
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
},
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
} = publishing;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
const SIZE_MB = 1000000;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
export const validateFileForPublish = file => {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
let contentType = file.type;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
let mediaType = contentType ? contentType.substr(0, contentType.indexOf('/')) : '';
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (!file) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error('no file provided');
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (/'/.test(file.name)) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error('apostrophes are not allowed in the file name');
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (Object.keys(customByContentType).includes(contentType)) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (file.size > customByContentType[contentType]) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
`Sorry, type ${contentType} is limited to ${customByContentType[contentType] / SIZE_MB} MB.`
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
} else {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
switch (mediaType) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
case 'image':
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (file.size > maxSizeImage) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(`Sorry, type ${mediaType} is limited to ${maxSizeImage / SIZE_MB} MB.`);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
break;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
case 'audio':
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (file.size > maxSizeAudio) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(`Sorry, type ${mediaType} is limited to ${maxSizeAudio / SIZE_MB} MB.`);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
break;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
case 'video':
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (file.size > maxSizeVideo) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(`Sorry, type ${mediaType} is limited to ${maxSizeVideo / SIZE_MB} MB.`);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
break;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
case 'text':
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (file.size > maxSizeText) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(`Sorry, type ${mediaType} is limited to ${maxSizeText / SIZE_MB} MB.`);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
break;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
case 'model':
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (file.size > maxSizeModel) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(`Sorry, type ${mediaType} is limited to ${maxSizeModel / SIZE_MB} MB.`);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
break;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
case 'application':
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
if (file.size > maxSizeApplication) {
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
`Sorry, type ${mediaType} is limited to ${maxSizeApplication / SIZE_MB} MB.`
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
break;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
default:
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
throw new Error(`Missing or unrecognized file type`);
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
return false;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
}
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
return file;
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.
};
skhameneh commented 2019-02-07 04:06:31 +01:00 (Migrated from github.com)
Review

Much of this is duplicated in the other file I commented.

Much of this is duplicated in the other file I commented.