updated input msgs and destructuring

This commit is contained in:
bill bittner 2017-09-25 11:55:56 -07:00
parent 250ead165b
commit ede4d4804f
3 changed files with 9 additions and 15 deletions

View file

@ -7,8 +7,6 @@ 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
@ -16,7 +14,7 @@ module.exports = {
if (result === true) { if (result === true) {
return lbryApi.publishClaim(publishParams); return lbryApi.publishClaim(publishParams);
} else { } else {
return new Error('That name has already been claimed by spee.ch.'); return new Error('That name is already in use by spee.ch.');
} }
}) })
// 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)
@ -60,9 +58,7 @@ module.exports = {
// create the records // create the records
return Promise.all([db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim')]); return Promise.all([db.upsert(db.File, fileRecord, upsertCriteria, 'File'), db.upsert(db.Claim, claimRecord, upsertCriteria, 'Claim')]);
}) })
.then(result => { .then(([file, claim]) => {
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.setClaim(claim), claim.setFile(file)]); return Promise.all([file.setClaim(claim), claim.setFile(file)]);
}) })

View file

@ -29,7 +29,7 @@ module.exports = {
// validate claim name // validate claim name
const invalidCharacters = /[^A-Za-z0-9,-]/.exec(name); const invalidCharacters = /[^A-Za-z0-9,-]/.exec(name);
if (invalidCharacters) { if (invalidCharacters) {
throw new Error('The claim name you provided is not allowed. Only the following characters are allowed: A-Z, a-z, 0-9, and "-"'); throw new Error('The url name you provided is not allowed. Only the following characters are allowed: A-Z, a-z, 0-9, and "-"');
} }
// validate license // validate license
if ((license.indexOf('Public Domain') === -1) && (license.indexOf('Creative Commons') === -1)) { if ((license.indexOf('Public Domain') === -1) && (license.indexOf('Creative Commons') === -1)) {

View file

@ -15,7 +15,6 @@ module.exports = new PassportLocalStrategy(
logger.debug('new channel signup request'); logger.debug('new channel signup request');
const address = config.get('WalletConfig.LbryClaimAddress'); const address = config.get('WalletConfig.LbryClaimAddress');
let user; let user;
let certificate;
// server-side validaton of inputs (username, password) // server-side validaton of inputs (username, password)
// create the channel and retrieve the metadata // create the channel and retrieve the metadata
@ -26,7 +25,6 @@ module.exports = new PassportLocalStrategy(
channelName : username, channelName : username,
channelClaimId: tx.claim_id, channelClaimId: tx.claim_id,
password : password, password : password,
// address,
}; };
logger.debug('userData >', userData); logger.debug('userData >', userData);
// create certificate record // create certificate record
@ -39,16 +37,16 @@ module.exports = new PassportLocalStrategy(
// save user and certificate to db // save user and certificate to db
return Promise.all([db.User.create(userData), db.Certificate.create(certificateData)]); return Promise.all([db.User.create(userData), db.Certificate.create(certificateData)]);
}) })
.then(result => { .then(([newUser, newCertificate]) => {
user = result[0]; user = newUser; // save outside scope of this function
certificate = result[1];
logger.debug('user and certificate successfully created'); logger.debug('user and certificate successfully created');
logger.debug('user result >', user.dataValues); logger.debug('user result >', newUser.dataValues);
logger.debug('certificate result >', certificate.dataValues); logger.debug('certificate result >', newCertificate.dataValues);
// associate the instances // associate the instances
return Promise.all([certificate.setUser(user), user.setCertificate(certificate)]); return Promise.all([newCertificate.setUser(newUser), newUser.setCertificate(newCertificate)]);
}).then(() => { }).then(() => {
logger.debug('user and certificate successfully associated'); logger.debug('user and certificate successfully associated');
logger.debug('user ===', user.dataValues);
return done(null, user); return done(null, user);
}) })
.catch(error => { .catch(error => {