fixed publish associations and db.Claim info

This commit is contained in:
bill bittner 2017-09-21 12:05:04 -07:00
parent ba7e19a498
commit 99dc857380
4 changed files with 42 additions and 17 deletions

View file

@ -7,6 +7,8 @@ module.exports = {
publish (publishParams, fileName, fileType) {
return new Promise((resolve, reject) => {
let publishResults = {};
let file;
let claim;
// 1. make sure the name is available
publishHelpers.checkClaimNameAvailability(publishParams.name)
// 2. publish the file
@ -18,12 +20,14 @@ module.exports = {
}
})
// 3. upsert File record (update is in case the claim has been published before by this daemon)
.then(result => {
let fileRecord;
let upsertCriteria;
publishResults = result;
logger.info(`Successfully published ${fileName}`, publishResults);
fileRecord = {
.then(tx => {
logger.info(`Successfully published ${fileName}`, tx);
publishResults = tx;
return db.User.findOne({where: {channelName: publishParams.channel_name}});
})
.then(user => {
logger.debug('found user', user.datavalues);
const fileRecord = {
name : publishParams.name,
claimId : publishResults.claim_id,
title : publishParams.metadata.title,
@ -36,16 +40,31 @@ module.exports = {
fileType,
nsfw : publishParams.metadata.nsfw,
};
upsertCriteria = {
const claimRecord = {
name : publishParams.name,
claimId : publishResults.claim_id,
title : publishParams.metadata.title,
description : publishParams.metadata.description,
address : publishParams.claim_address,
outpoint : `${publishResults.txid}:${publishResults.nout}`,
height : 0,
contentType : fileType,
nsfw : publishParams.metadata.nsfw,
certificateId: user.channelClaimId,
amount : publishParams.bid,
};
const upsertCriteria = {
name : publishParams.name,
claimId: publishResults.claim_id,
};
// create the records
return Promise.all([db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.Claim, fileRecord, upsertCriteria, 'Claim')]);
return Promise.all([db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim')]);
})
.then((file, claim) => {
.then(result => {
file = result[0];
claim = result[1];
logger.debug('File and Claim records successfully created');
return Promise.all([file.setClaims(claim), claim.setFiles(file)]);
return Promise.all([file.setClaim(claim), claim.setFile(file)]);
})
.then(() => {
logger.debug('File and Claim records successfully associated');

View file

@ -84,11 +84,11 @@ module.exports = {
description,
title,
author : 'spee.ch',
language : 'en',
language: 'en',
license,
nsfw,
channel_name: channel,
},
channel_name : channel,
claim_address: claimAddress,
// change_address: changeAddress,
};

View file

@ -20,11 +20,11 @@ module.exports = new PassportLocalStrategy(
// create the channel and retrieve the metadata
return lbryApi.createChannel(username)
.then(channelTx => {
.then(tx => {
// create user record
const userData = {
channelName : username,
channelClaimId: channelTx.claim_id,
channelClaimId: tx.claim_id,
password : password,
address,
};
@ -32,7 +32,7 @@ module.exports = new PassportLocalStrategy(
// create certificate record
const certificateData = {
address,
claimId: channelTx.claim_id,
claimId: tx.claim_id,
name : username,
};
logger.debug('certificateData >', certificateData);
@ -47,7 +47,7 @@ module.exports = new PassportLocalStrategy(
logger.debug('certificate result >', certificate.dataValues);
// associate the instances
return Promise.all([certificate.setUser(user), user.setCertificate(certificate)]);
}).then(result => {
}).then(() => {
logger.debug('user and certificate successfully associated');
return done(null, user);
})

View file

@ -35,6 +35,12 @@ module.exports = (app, siofu, hostedContentPath) => {
if (file.success) {
logger.debug(`Client successfully uploaded ${file.name}`);
socket.emit('publish-status', 'File upload successfully completed. Your image is being published to LBRY (this might take a second)...');
/*
NOTE: need to validate that client has the credentials to the channel they chose
otherwise they could circumvent security client side.
*/
// prepare the publish parameters
const publishParams = publishHelpers.createPublishParams(file.meta.name, file.pathName, file.meta.title, file.meta.description, file.meta.license, file.meta.nsfw, file.meta.channel);
// publish the file