Refactor publish and validation and servability for all file types #902
|
@ -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
|
||||||
|
|
75
utils/validateFileForPublish.js
Normal file
|
@ -0,0 +1,75 @@
|
||||||
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';
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
const {
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
fileSizeLimits: {
|
||||||
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,
|
||||||
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,
|
||||||
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,
|
||||||
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,
|
||||||
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,
|
||||||
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,
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
customByContentType,
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
},
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
} = publishing;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
|
||||||
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;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
|
||||||
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 => {
|
||||||
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;
|
||||||
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('/')) : '';
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
if (!file) {
|
||||||
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');
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
|
||||||
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)) {
|
||||||
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');
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
|
||||||
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)) {
|
||||||
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]) {
|
||||||
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(
|
||||||
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.`
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
} else {
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
switch (mediaType) {
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
case 'image':
|
||||||
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) {
|
||||||
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.`);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
break;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
case 'audio':
|
||||||
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) {
|
||||||
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.`);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
break;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
case 'video':
|
||||||
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) {
|
||||||
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.`);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
break;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
case 'text':
|
||||||
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) {
|
||||||
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.`);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
break;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
case 'model':
|
||||||
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) {
|
||||||
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.`);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
break;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
case 'application':
|
||||||
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) {
|
||||||
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(
|
||||||
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.`
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
break;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
default:
|
||||||
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`);
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
return false;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
}
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
return file;
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
|||||||
|
};
|
||||||
Much of this is duplicated in the other file I commented. Much of this is duplicated in the other file I commented.
|
Much of this is duplicated in the other file I commented.