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;
}
if (nsfw) {
publishParams.tags.push = 'mature';
publishParams.tags = 'mature';
}
// add channel details if publishing to a channel
if (channelClaimId) {
if (channelName && channelClaimId) {
publishParams['channel_id'] = channelClaimId;
publishParams['channel_name'] = channelName;
}
// log params
logger.debug('publish params:', publishParams);

View file

@ -7,6 +7,15 @@ const createThumbnailPublishParams = (thumbnailFilePath, claimName, license, lic
}
logger.debug(`Creating Thumbnail Publish Parameters`);
// 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 {
name: `${claimName}-thumb`,
file_path: thumbnailFilePath,

View file

@ -12,24 +12,32 @@ const publish = async (publishParams, fileName, fileType) => {
let channel;
let fileRecord;
let newFile = Boolean(publishParams.file_path);
let publishResultsOutput;
try {
publishResults = await publishClaim(publishParams);
publishResultsOutput = publishResults && publishResults.outputs && publishResults.outputs[0];
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
if (publishParams.channel_name) {
logger.debug(`this claim was published in channel: ${publishParams.channel_name}`);
channel = await db.Channel.findOne({
where: {
channelName: publishParams.channel_name,
},
});
} else {
channel = null;
}
const certificateId = channel ? channel.channelClaimId : null;
const channelName = channel ? channel.channelName : null;
// if (publishParams.channel_name) {
// logger.debug(`this claim was published in channel: ${publishParams.channel_name}`);
// channel = await db.Channel.findOne({
// where: {
// channelName: publishParams.channel_name,
// },
// });
// } else {
// channel = 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(
certificateId,
@ -37,7 +45,7 @@ const publish = async (publishParams, fileName, fileType) => {
fileName,
fileType,
publishParams,
publishResults
publishResultsOutput
);
const { claimId } = claimRecord;
const upsertCriteria = { name: publishParams.name, claimId };
@ -48,7 +56,7 @@ const publish = async (publishParams, fileName, fileType) => {
fileName,
fileType,
publishParams,
publishResults
publishResultsOutput
);
} else {
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 name = params.name;
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,
// and shop the outpoint to file_list.
return chainquery.claim.queries

View file

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

View file

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

View file

@ -2,7 +2,9 @@ const PassportLocalStrategy = require('passport-local').Strategy;
const { createChannel } = require('../../lbrynet');
const logger = require('winston');
const db = require('../../models');
const { publishing: { closedRegistration } } = require('@config/siteConfig');
const {
publishing: { closedRegistration },
} = require('@config/siteConfig');
module.exports = new PassportLocalStrategy(
{
@ -29,18 +31,22 @@ module.exports = new PassportLocalStrategy(
// create user record
const channelData = {
channelName: `@${username}`,
channelClaimId: tx.claim_id,
channelClaimId: tx.outputs[0].claim_id,
};
logger.verbose('channelData >', channelData);
// create certificate record
const certificateData = {
claimId: tx.claim_id,
claimId: tx.outputs[0].claim_id,
name: `@${username}`,
// address,
};
logger.verbose('certificateData >', certificateData);
// 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]) => {
logger.verbose('user and certificate successfully created');
@ -54,7 +60,10 @@ module.exports = new PassportLocalStrategy(
})
.then(() => {
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 => {
userInfo['shortChannelId'] = shortChannelId;