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) { publish (publishParams, fileName, fileType) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let publishResults = {}; let publishResults = {};
let file;
let claim;
// 1. make sure the name is available // 1. make sure the name is available
publishHelpers.checkClaimNameAvailability(publishParams.name) publishHelpers.checkClaimNameAvailability(publishParams.name)
// 2. publish the file // 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) // 3. upsert File record (update is in case the claim has been published before by this daemon)
.then(result => { .then(tx => {
let fileRecord; logger.info(`Successfully published ${fileName}`, tx);
let upsertCriteria; publishResults = tx;
publishResults = result; return db.User.findOne({where: {channelName: publishParams.channel_name}});
logger.info(`Successfully published ${fileName}`, publishResults); })
fileRecord = { .then(user => {
logger.debug('found user', user.datavalues);
const fileRecord = {
name : publishParams.name, name : publishParams.name,
claimId : publishResults.claim_id, claimId : publishResults.claim_id,
title : publishParams.metadata.title, title : publishParams.metadata.title,
@ -36,16 +40,31 @@ module.exports = {
fileType, fileType,
nsfw : publishParams.metadata.nsfw, 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, name : publishParams.name,
claimId: publishResults.claim_id, claimId: publishResults.claim_id,
}; };
// create the records // 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'); 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(() => { .then(() => {
logger.debug('File and Claim records successfully associated'); logger.debug('File and Claim records successfully associated');

View file

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

View file

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

View file

@ -35,6 +35,12 @@ module.exports = (app, siofu, hostedContentPath) => {
if (file.success) { if (file.success) {
logger.debug(`Client successfully uploaded ${file.name}`); 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)...'); 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 // 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); 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 // publish the file