moved thumbnail check to server side
This commit is contained in:
parent
b3e6c89f0e
commit
d28a5758dd
4 changed files with 53 additions and 54 deletions
|
@ -1,6 +1,6 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { site, wallet } = require('../config/speechConfig.js');
|
const { site, wallet, publish } = require('../config/speechConfig.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parsePublishApiRequestBody ({name, nsfw, license, title, description, thumbnail}) {
|
parsePublishApiRequestBody ({name, nsfw, license, title, description, thumbnail}) {
|
||||||
|
@ -28,7 +28,7 @@ module.exports = {
|
||||||
thumbnail,
|
thumbnail,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
parsePublishApiRequestFiles ({file}) {
|
parsePublishApiRequestFiles ({file, thumbnail}) {
|
||||||
// make sure a file was provided
|
// make sure a file was provided
|
||||||
if (!file) {
|
if (!file) {
|
||||||
throw new Error('no file with key of [file] found in request');
|
throw new Error('no file with key of [file] found in request');
|
||||||
|
@ -53,6 +53,9 @@ module.exports = {
|
||||||
fileName : file.name,
|
fileName : file.name,
|
||||||
filePath : file.path,
|
filePath : file.path,
|
||||||
fileType : file.type,
|
fileType : file.type,
|
||||||
|
thumbnailFileName: (thumbnail ? thumbnail.name : null),
|
||||||
|
thumbnailFilePath: (thumbnail ? thumbnail.path : null),
|
||||||
|
thumbnailFileType: (thumbnail ? thumbnail.type : null),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
parsePublishApiChannel ({channelName, channelPassword}, user) {
|
parsePublishApiChannel ({channelName, channelPassword}, user) {
|
||||||
|
@ -138,7 +141,7 @@ module.exports = {
|
||||||
claim_address: wallet.lbryClaimAddress,
|
claim_address: wallet.lbryClaimAddress,
|
||||||
};
|
};
|
||||||
// add thumbnail to channel if video
|
// add thumbnail to channel if video
|
||||||
if (thumbnail !== null) {
|
if (thumbnail) {
|
||||||
publishParams['metadata']['thumbnail'] = thumbnail;
|
publishParams['metadata']['thumbnail'] = thumbnail;
|
||||||
}
|
}
|
||||||
// add channel to params, if applicable
|
// add channel to params, if applicable
|
||||||
|
@ -147,6 +150,29 @@ module.exports = {
|
||||||
}
|
}
|
||||||
return publishParams;
|
return publishParams;
|
||||||
},
|
},
|
||||||
|
createThumbnailPublishParams (thumbnailFilePath, claimName, license, nsfw) {
|
||||||
|
if (!thumbnailFilePath) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
logger.debug(`Creating Thumbnail Publish Parameters`);
|
||||||
|
// create the publish params
|
||||||
|
return {
|
||||||
|
name : `${claimName}-thumb`,
|
||||||
|
file_path: thumbnailFilePath,
|
||||||
|
bid : 0.01,
|
||||||
|
metadata : {
|
||||||
|
title : `${claimName} thumbnail`,
|
||||||
|
description: `a thumbnail for ${claimName}`,
|
||||||
|
author : site.title,
|
||||||
|
language : 'en',
|
||||||
|
license,
|
||||||
|
nsfw,
|
||||||
|
},
|
||||||
|
claim_address: wallet.lbryClaimAddress,
|
||||||
|
channel_name : publish.thumbnailChannel,
|
||||||
|
channel_id : publish.thumbnailChannelId,
|
||||||
|
};
|
||||||
|
},
|
||||||
deleteTemporaryFile (filePath) {
|
deleteTemporaryFile (filePath) {
|
||||||
fs.unlink(filePath, err => {
|
fs.unlink(filePath, err => {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
|
@ -34,20 +34,17 @@ function * publishFile (action) {
|
||||||
publishMetadata['thumbnail'] = createThumbnailUrl(thumbnailChannel, thumbnailChannelId, claim, host);
|
publishMetadata['thumbnail'] = createThumbnailUrl(thumbnailChannel, thumbnailChannelId, claim, host);
|
||||||
}
|
}
|
||||||
// create form data for main publish
|
// create form data for main publish
|
||||||
const publishFormData = createPublishFormData(file, publishMetadata);
|
const publishFormData = createPublishFormData(file, thumbnail, publishMetadata);
|
||||||
// make the publish request
|
// make the publish request
|
||||||
const publishChannel = yield call(makePublishRequestChannel, publishFormData);
|
const publishChannel = yield call(makePublishRequestChannel, publishFormData);
|
||||||
let publishInProgress = true;
|
while (true) {
|
||||||
while (publishInProgress) {
|
|
||||||
const {loadStart, progress, load, success, error} = yield take(publishChannel);
|
const {loadStart, progress, load, success, error} = yield take(publishChannel);
|
||||||
if (error) {
|
if (error) {
|
||||||
yield put(updatePublishStatus(publishStates.FAILED, error.message));
|
return yield put(updatePublishStatus(publishStates.FAILED, error.message));
|
||||||
publishInProgress = false;
|
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
yield put(clearFile());
|
yield put(clearFile());
|
||||||
history.push(`/${success.data.claimId}/${success.data.name}`);
|
return history.push(`/${success.data.claimId}/${success.data.name}`);
|
||||||
publishInProgress = false;
|
|
||||||
}
|
}
|
||||||
if (loadStart) {
|
if (loadStart) {
|
||||||
yield put(updatePublishStatus(publishStates.LOAD_START, null));
|
yield put(updatePublishStatus(publishStates.LOAD_START, null));
|
||||||
|
@ -59,41 +56,6 @@ function * publishFile (action) {
|
||||||
yield put(updatePublishStatus(publishStates.PUBLISHING, null));
|
yield put(updatePublishStatus(publishStates.PUBLISHING, null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// publish thumbnail
|
|
||||||
if (thumbnail) {
|
|
||||||
// create form data for thumbnail publish
|
|
||||||
const thumbnailMetadata = {
|
|
||||||
name : `${claim}-thumb`,
|
|
||||||
title : `${claim} thumbnail`,
|
|
||||||
description : `a thumbnail for ${claim}`,
|
|
||||||
license : publishMetadata.license,
|
|
||||||
nsfw : publishMetadata.nsfw,
|
|
||||||
type : 'image/png',
|
|
||||||
channel_name: thumbnailChannel,
|
|
||||||
channel_id : thumbnailChannelId,
|
|
||||||
};
|
|
||||||
const thumbnailFormData = createPublishFormData(thumbnail, thumbnailMetadata);
|
|
||||||
// make the publish reqeust
|
|
||||||
const thumbnailPublishChannel = yield call(makePublishRequestChannel, thumbnailFormData);
|
|
||||||
while (true) {
|
|
||||||
const {loadStart, progress, load, success, error} = yield take(thumbnailPublishChannel);
|
|
||||||
if (error) {
|
|
||||||
return console.log('thumbnail error:', error.message);
|
|
||||||
}
|
|
||||||
if (success) {
|
|
||||||
return console.log('thumbnail success:', success.data);
|
|
||||||
}
|
|
||||||
if (loadStart) {
|
|
||||||
console.log('thumbnail load started.');
|
|
||||||
}
|
|
||||||
if (progress) {
|
|
||||||
console.log('thumbnail progress:', `${progress}%`);
|
|
||||||
}
|
|
||||||
if (load) {
|
|
||||||
console.log('thumbnail load completed.');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export function * watchPublishStart () {
|
export function * watchPublishStart () {
|
||||||
|
|
|
@ -13,10 +13,14 @@ export const createPublishMetadata = (claim, { type }, { title, description, lic
|
||||||
return metadata;
|
return metadata;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createPublishFormData = (file, metadata) => {
|
export const createPublishFormData = (file, thumbnail, metadata) => {
|
||||||
let fd = new FormData();
|
let fd = new FormData();
|
||||||
// append file
|
// append file
|
||||||
fd.append('file', file);
|
fd.append('file', file);
|
||||||
|
// append thumbnail
|
||||||
|
if (thumbnail) {
|
||||||
|
fd.append('thumbnail', thumbnail);
|
||||||
|
}
|
||||||
// append metadata
|
// append metadata
|
||||||
for (let key in metadata) {
|
for (let key in metadata) {
|
||||||
if (metadata.hasOwnProperty(key)) {
|
if (metadata.hasOwnProperty(key)) {
|
||||||
|
|
|
@ -5,7 +5,7 @@ const multipartMiddleware = multipart({uploadDir: files.uploadDirectory});
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const { checkClaimNameAvailability, checkChannelAvailability, publish } = require('../controllers/publishController.js');
|
const { checkClaimNameAvailability, checkChannelAvailability, publish } = require('../controllers/publishController.js');
|
||||||
const { getClaimList, resolveUri, getClaim } = require('../helpers/lbryApi.js');
|
const { getClaimList, resolveUri, getClaim } = require('../helpers/lbryApi.js');
|
||||||
const { createPublishParams, parsePublishApiRequestBody, parsePublishApiRequestFiles, parsePublishApiChannel, addGetResultsToFileData, createFileData } = require('../helpers/publishHelpers.js');
|
const { addGetResultsToFileData, createFileData, createPublishParams, createThumbnailPublishParams, parsePublishApiRequestBody, parsePublishApiRequestFiles, parsePublishApiChannel } = require('../helpers/publishHelpers.js');
|
||||||
const errorHandlers = require('../helpers/errorHandlers.js');
|
const errorHandlers = require('../helpers/errorHandlers.js');
|
||||||
const { sendGAAnonymousPublishTiming, sendGAChannelPublishTiming } = require('../helpers/googleAnalytics.js');
|
const { sendGAAnonymousPublishTiming, sendGAChannelPublishTiming } = require('../helpers/googleAnalytics.js');
|
||||||
const { authenticateIfNoUserToken } = require('../auth/authentication.js');
|
const { authenticateIfNoUserToken } = require('../auth/authentication.js');
|
||||||
|
@ -135,14 +135,14 @@ module.exports = (app) => {
|
||||||
logger.debug('api/claim-publish body:', body);
|
logger.debug('api/claim-publish body:', body);
|
||||||
logger.debug('api/claim-publish files:', files);
|
logger.debug('api/claim-publish files:', files);
|
||||||
// define variables
|
// define variables
|
||||||
let name, fileName, filePath, fileType, nsfw, license, title, description, thumbnail, channelName, channelPassword;
|
let name, fileName, filePath, fileType, thumbnailFileName, thumbnailFilePath, thumbnailFileType, nsfw, license, title, description, thumbnail, channelName, channelPassword;
|
||||||
// record the start time of the request
|
// record the start time of the request
|
||||||
const publishStartTime = Date.now();
|
const publishStartTime = Date.now();
|
||||||
// validate the body and files of the request
|
// validate the body and files of the request
|
||||||
try {
|
try {
|
||||||
// validateApiPublishRequest(body, files);
|
// validateApiPublishRequest(body, files);
|
||||||
({name, nsfw, license, title, description, thumbnail} = parsePublishApiRequestBody(body));
|
({name, nsfw, license, title, description, thumbnail} = parsePublishApiRequestBody(body));
|
||||||
({fileName, filePath, fileType} = parsePublishApiRequestFiles(files));
|
({fileName, filePath, fileType, thumbnailFileName, thumbnailFilePath, thumbnailFileType} = parsePublishApiRequestFiles(files));
|
||||||
({channelName, channelPassword} = parsePublishApiChannel(body, user));
|
({channelName, channelPassword} = parsePublishApiChannel(body, user));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return res.status(400).json({success: false, message: error.message});
|
return res.status(400).json({success: false, message: error.message});
|
||||||
|
@ -161,9 +161,16 @@ module.exports = (app) => {
|
||||||
throw new Error('That name is already claimed by another user.');
|
throw new Error('That name is already claimed by another user.');
|
||||||
}
|
}
|
||||||
// create publish parameters object
|
// create publish parameters object
|
||||||
return createPublishParams(filePath, name, title, description, license, nsfw, thumbnail, channelName);
|
return Promise.all([
|
||||||
|
createPublishParams(filePath, name, title, description, license, nsfw, thumbnail, channelName),
|
||||||
|
createThumbnailPublishParams(thumbnailFilePath, name, license, nsfw),
|
||||||
|
]);
|
||||||
})
|
})
|
||||||
.then(publishParams => {
|
.then(([publishParams, thumbnailPublishParams]) => {
|
||||||
|
// publish the thumbnail
|
||||||
|
if (thumbnailPublishParams) {
|
||||||
|
publish(thumbnailPublishParams, thumbnailFileName, thumbnailFileType);
|
||||||
|
}
|
||||||
// publish the asset
|
// publish the asset
|
||||||
return publish(publishParams, fileName, fileType);
|
return publish(publishParams, fileName, fileType);
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue