fixes!
This commit is contained in:
Tom 2019-05-24 16:39:46 -04:00
parent 1b069ba2a1
commit adbafa4194
7 changed files with 71 additions and 57 deletions

View file

@ -47,11 +47,12 @@ const createPublishParams = (
publishParams['thumbnail_url'] = thumbnail; publishParams['thumbnail_url'] = thumbnail;
} }
if (nsfw) { if (nsfw) {
publishParams.tags.push = 'mature'; publishParams.tags = 'mature';
} }
// add channel details if publishing to a channel // add channel details if publishing to a channel
if (channelClaimId) { if (channelName && channelClaimId) {
publishParams['channel_id'] = channelClaimId; publishParams['channel_id'] = channelClaimId;
publishParams['channel_name'] = channelName;
} }
// log params // log params
logger.debug('publish params:', publishParams); logger.debug('publish params:', publishParams);

View file

@ -7,6 +7,15 @@ const createThumbnailPublishParams = (thumbnailFilePath, claimName, license, lic
} }
logger.debug(`Creating Thumbnail Publish Parameters`); logger.debug(`Creating Thumbnail Publish Parameters`);
// create the publish params // create the publish params
if (license === null || license.trim() === '') {
license = ''; // default to empty string
}
// provide default for licenseUrl
if (licenseUrl === null || licenseUrl.trim() === '') {
licenseUrl = ''; // default to empty string
}
return { return {
name: `${claimName}-thumb`, name: `${claimName}-thumb`,
file_path: thumbnailFilePath, file_path: thumbnailFilePath,

View file

@ -12,24 +12,32 @@ const publish = async (publishParams, fileName, fileType) => {
let channel; let channel;
let fileRecord; let fileRecord;
let newFile = Boolean(publishParams.file_path); let newFile = Boolean(publishParams.file_path);
let publishResultsOutput;
try { try {
publishResults = await publishClaim(publishParams); publishResults = await publishClaim(publishParams);
publishResultsOutput = publishResults && publishResults.outputs && publishResults.outputs[0];
logger.verbose(`Successfully published ${publishParams.name} ${fileName}`, publishResults); logger.verbose(`Successfully published ${publishParams.name} ${fileName}`, publishResults);
const outpoint = `${publishResults.outputs[0].txid}:${publishResults.outputs[0].nout}`; const outpoint = `${publishResultsOutput.txid}:${publishResultsOutput.nout}`;
// get the channel information // get the channel information
if (publishParams.channel_name) { // if (publishParams.channel_name) {
logger.debug(`this claim was published in channel: ${publishParams.channel_name}`); // logger.debug(`this claim was published in channel: ${publishParams.channel_name}`);
channel = await db.Channel.findOne({ // channel = await db.Channel.findOne({
where: { // where: {
channelName: publishParams.channel_name, // channelName: publishParams.channel_name,
}, // },
}); // });
} else { // } else {
channel = null; // channel = null;
} // }
const certificateId = channel ? channel.channelClaimId : null;
const channelName = channel ? channel.channelName : null; const certificateId = publishResultsOutput.signing_channel
? publishResultsOutput.signing_channel.claim_id
: null;
const channelName = publishResultsOutput.signing_channel
? publishResultsOutput.signing_channel.name
: null;
const claimRecord = await createClaimRecordDataAfterPublish( const claimRecord = await createClaimRecordDataAfterPublish(
certificateId, certificateId,
@ -37,7 +45,7 @@ const publish = async (publishParams, fileName, fileType) => {
fileName, fileName,
fileType, fileType,
publishParams, publishParams,
publishResults publishResultsOutput
); );
const { claimId } = claimRecord; const { claimId } = claimRecord;
const upsertCriteria = { name: publishParams.name, claimId }; const upsertCriteria = { name: publishParams.name, claimId };
@ -48,7 +56,7 @@ const publish = async (publishParams, fileName, fileType) => {
fileName, fileName,
fileType, fileType,
publishParams, publishParams,
publishResults publishResultsOutput
); );
} else { } else {
fileRecord = await db.File.findOne({ where: { claimId } }).then(result => result.dataValues); fileRecord = await db.File.findOne({ where: { claimId } }).then(result => result.dataValues);

View file

@ -14,7 +14,7 @@ const chainquery = require('chainquery').default;
const fileAvailability = ({ ip, originalUrl, params }, res) => { const fileAvailability = ({ ip, originalUrl, params }, res) => {
const name = params.name; const name = params.name;
const claimId = params.claimId; const claimId = params.claimId;
logger.debug(`fileAvailability params: name:${name} claimId:${claimId}`); logger.verbose(`fileAvailability params: name:${name} claimId:${claimId}`);
// TODO: we probably eventually want to check the publishCache for the claimId too, // TODO: we probably eventually want to check the publishCache for the claimId too,
// and shop the outpoint to file_list. // and shop the outpoint to file_list.
return chainquery.claim.queries return chainquery.claim.queries

View file

@ -6,16 +6,19 @@ const createClaimRecordDataAfterPublish = (
fileName, fileName,
fileType, fileType,
publishParams, publishParams,
publishResults publishResultsOutput
) => { ) => {
const { const {
name, name,
metadata: { title, description, thumbnail, nsfw }, title,
description,
thumbnail,
nsfw,
claim_address: address, claim_address: address,
bid: amount, bid: amount,
} = publishParams; } = publishParams;
const { claim_id: claimId, txid, nout } = publishResults; const { claim_id: claimId, txid, nout } = publishResultsOutput;
return db.Claim.getCurrentHeight().then(height => { return db.Claim.getCurrentHeight().then(height => {
return { return {

View file

@ -1,22 +1,11 @@
const getMediaDimensions = require('../../utils/getMediaDimensions.js'); const getMediaDimensions = require('../../utils/getMediaDimensions.js');
async function createFileRecordDataAfterGet (resolveResult, getResult) { async function createFileRecordDataAfterGet(resolveResult, getResult) {
const { const { name, claimId, outpoint, contentType: fileType } = resolveResult;
name,
claimId,
outpoint,
contentType: fileType,
} = resolveResult;
const { const { file_name: fileName, download_path: filePath } = getResult;
file_name: fileName,
download_path: filePath,
} = getResult;
const { const { height: fileHeight, width: fileWidth } = await getMediaDimensions(fileType, filePath);
height: fileHeight,
width: fileWidth,
} = await getMediaDimensions(fileType, filePath);
return { return {
name, name,
@ -30,22 +19,17 @@ async function createFileRecordDataAfterGet (resolveResult, getResult) {
}; };
} }
async function createFileRecordDataAfterPublish (fileName, fileType, publishParams, publishResults) { async function createFileRecordDataAfterPublish(
const { fileName,
name, fileType,
file_path: filePath, publishParams,
} = publishParams; publishResultsOutput
) {
const { name, file_path: filePath } = publishParams;
const { const { claim_id: claimId, txid, nout } = publishResultsOutput;
claim_id: claimId,
txid,
nout,
} = publishResults;
const { const { height: fileHeight, width: fileWidth } = await getMediaDimensions(fileType, filePath);
height: fileHeight,
width: fileWidth,
} = await getMediaDimensions(fileType, filePath);
return { return {
name, name,

View file

@ -2,7 +2,9 @@ const PassportLocalStrategy = require('passport-local').Strategy;
const { createChannel } = require('../../lbrynet'); const { createChannel } = require('../../lbrynet');
const logger = require('winston'); const logger = require('winston');
const db = require('../../models'); const db = require('../../models');
const { publishing: { closedRegistration } } = require('@config/siteConfig'); const {
publishing: { closedRegistration },
} = require('@config/siteConfig');
module.exports = new PassportLocalStrategy( module.exports = new PassportLocalStrategy(
{ {
@ -28,19 +30,23 @@ module.exports = new PassportLocalStrategy(
logger.verbose('userData >', userData); logger.verbose('userData >', userData);
// create user record // create user record
const channelData = { const channelData = {
channelName : `@${username}`, channelName: `@${username}`,
channelClaimId: tx.claim_id, channelClaimId: tx.outputs[0].claim_id,
}; };
logger.verbose('channelData >', channelData); logger.verbose('channelData >', channelData);
// create certificate record // create certificate record
const certificateData = { const certificateData = {
claimId: tx.claim_id, claimId: tx.outputs[0].claim_id,
name : `@${username}`, name: `@${username}`,
// address, // address,
}; };
logger.verbose('certificateData >', certificateData); logger.verbose('certificateData >', certificateData);
// save user and certificate to db // save user and certificate to db
return Promise.all([db.User.create(userData), db.Channel.create(channelData), db.Certificate.create(certificateData)]); return Promise.all([
db.User.create(userData),
db.Channel.create(channelData),
db.Certificate.create(certificateData),
]);
}) })
.then(([newUser, newChannel, newCertificate]) => { .then(([newUser, newChannel, newCertificate]) => {
logger.verbose('user and certificate successfully created'); logger.verbose('user and certificate successfully created');
@ -54,7 +60,10 @@ module.exports = new PassportLocalStrategy(
}) })
.then(() => { .then(() => {
logger.verbose('user and certificate successfully associated'); logger.verbose('user and certificate successfully associated');
return db.Certificate.getShortChannelIdFromLongChannelId(userInfo.channelClaimId, userInfo.channelName); return db.Certificate.getShortChannelIdFromLongChannelId(
userInfo.channelClaimId,
userInfo.channelName
);
}) })
.then(shortChannelId => { .then(shortChannelId => {
userInfo['shortChannelId'] = shortChannelId; userInfo['shortChannelId'] = shortChannelId;