Merge pull request #382 from lbryio/348-multiple-wallet-addresses
fix: updated claim name availability check to support multiple claim addresses
This commit is contained in:
commit
6f3ee0eb30
7 changed files with 61 additions and 73 deletions
|
@ -1,7 +1,4 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
wallet: {
|
|
||||||
lbryClaimAddress: null, // choose an address from your lbry wallet
|
|
||||||
},
|
|
||||||
analytics: {
|
analytics: {
|
||||||
googleId: null, // google id for analytics tracking; leave `null` if not applicable
|
googleId: null, // google id for analytics tracking; leave `null` if not applicable
|
||||||
},
|
},
|
||||||
|
@ -29,8 +26,10 @@ module.exports = {
|
||||||
description: 'Open-source, decentralized image and video sharing.',
|
description: 'Open-source, decentralized image and video sharing.',
|
||||||
},
|
},
|
||||||
publish: {
|
publish: {
|
||||||
thumbnailChannel : '@channelName', // create a channel to use for thumbnail images
|
primaryClaimAddress : null, // choose any address from your lbry wallet
|
||||||
thumbnailChannelId: 'xyz123...', // the channel_id (claim id) for the channel above
|
additionalClaimAddresses: [], // // optional: add previously used claim addresses
|
||||||
|
thumbnailChannel : '@channelName', // create a channel to use for thumbnail images
|
||||||
|
thumbnailChannelId : 'xyz123...', // the channel_id (claim id) for the channel above
|
||||||
},
|
},
|
||||||
claim: {
|
claim: {
|
||||||
defaultTitle : 'Spee.ch',
|
defaultTitle : 'Spee.ch',
|
||||||
|
|
|
@ -2,7 +2,9 @@ const logger = require('winston');
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const lbryApi = require('../helpers/lbryApi.js');
|
const lbryApi = require('../helpers/lbryApi.js');
|
||||||
const publishHelpers = require('../helpers/publishHelpers.js');
|
const publishHelpers = require('../helpers/publishHelpers.js');
|
||||||
const config = require('../config/speechConfig.js');
|
const { publish : { primaryClaimAddress, additionalClaimAddresses } } = require('../config/speechConfig.js');
|
||||||
|
const Sequelize = require('sequelize');
|
||||||
|
const Op = Sequelize.Op;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
publish (publishParams, fileName, fileType) {
|
publish (publishParams, fileName, fileType) {
|
||||||
|
@ -87,37 +89,42 @@ module.exports = {
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
claimNameIsAvailable (name) {
|
claimNameIsAvailable (name) {
|
||||||
|
const claimAddresses = additionalClaimAddresses || [];
|
||||||
|
claimAddresses.push(primaryClaimAddress);
|
||||||
// find any records where the name is used
|
// find any records where the name is used
|
||||||
return db.File.findAll({ where: { name } })
|
return db.Claim
|
||||||
|
.findAll({
|
||||||
|
attributes: ['address'],
|
||||||
|
where : {
|
||||||
|
name,
|
||||||
|
address: {
|
||||||
|
[Op.or]: claimAddresses,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result.length >= 1) {
|
if (result.length >= 1) {
|
||||||
const claimAddress = config.wallet.lbryClaimAddress;
|
throw new Error('That claim is already in use');
|
||||||
// filter out any results that were not published from spee.ch's wallet address
|
|
||||||
const filteredResult = result.filter((claim) => {
|
|
||||||
return (claim.address === claimAddress);
|
|
||||||
});
|
|
||||||
// return based on whether any non-spee.ch claims were left
|
|
||||||
if (filteredResult.length >= 1) {
|
|
||||||
throw new Error('That claim is already in use');
|
|
||||||
};
|
|
||||||
return name;
|
|
||||||
};
|
};
|
||||||
return name;
|
return name;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
throw error;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
checkChannelAvailability (name) {
|
checkChannelAvailability (name) {
|
||||||
return new Promise((resolve, reject) => {
|
return db.Channel
|
||||||
// find any records where the name is used
|
.findAll({
|
||||||
db.Channel.findAll({ where: { channelName: name } })
|
where: { channelName: name },
|
||||||
.then(result => {
|
})
|
||||||
if (result.length >= 1) {
|
.then(result => {
|
||||||
return resolve(false);
|
if (result.length >= 1) {
|
||||||
}
|
throw new Error('That channel has already been claimed');
|
||||||
resolve(true);
|
}
|
||||||
})
|
return name;
|
||||||
.catch(error => {
|
})
|
||||||
reject(error);
|
.catch(error => {
|
||||||
});
|
throw error;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const { site, wallet, publish } = require('../config/speechConfig.js');
|
const { site, publish } = require('../config/speechConfig.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
parsePublishApiRequestBody ({name, nsfw, license, title, description, thumbnail}) {
|
parsePublishApiRequestBody ({name, nsfw, license, title, description, thumbnail}) {
|
||||||
|
@ -114,7 +114,7 @@ module.exports = {
|
||||||
license,
|
license,
|
||||||
nsfw,
|
nsfw,
|
||||||
},
|
},
|
||||||
claim_address: wallet.lbryClaimAddress,
|
claim_address: publish.primaryClaimAddress,
|
||||||
};
|
};
|
||||||
// add thumbnail to channel if video
|
// add thumbnail to channel if video
|
||||||
if (thumbnail) {
|
if (thumbnail) {
|
||||||
|
@ -140,7 +140,7 @@ module.exports = {
|
||||||
license,
|
license,
|
||||||
nsfw,
|
nsfw,
|
||||||
},
|
},
|
||||||
claim_address: wallet.lbryClaimAddress,
|
claim_address: publish.primaryClaimAddress,
|
||||||
channel_name : publish.thumbnailChannel,
|
channel_name : publish.thumbnailChannel,
|
||||||
channel_id : publish.thumbnailChannelId,
|
channel_id : publish.thumbnailChannelId,
|
||||||
};
|
};
|
||||||
|
|
|
@ -349,14 +349,13 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
|
||||||
where: { name, claimId },
|
where: { name, claimId },
|
||||||
})
|
})
|
||||||
.then(claimArray => {
|
.then(claimArray => {
|
||||||
logger.debug('claims found on resolve:', claimArray.length);
|
|
||||||
switch (claimArray.length) {
|
switch (claimArray.length) {
|
||||||
case 0:
|
case 0:
|
||||||
return resolve(null);
|
return resolve(null);
|
||||||
case 1:
|
case 1:
|
||||||
return resolve(prepareClaimData(claimArray[0].dataValues));
|
return resolve(prepareClaimData(claimArray[0].dataValues));
|
||||||
default:
|
default:
|
||||||
logger.error(`more than one entry matches that name (${name}) and claimID (${claimId})`);
|
logger.error(`more than one record matches ${name}#${claimId} in db.Claim`);
|
||||||
return resolve(prepareClaimData(claimArray[0].dataValues));
|
return resolve(prepareClaimData(claimArray[0].dataValues));
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
// const fs = require('fs');
|
|
||||||
// const path = require('path');
|
|
||||||
const Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
// const basename = path.basename(module.filename);
|
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const config = require('../config/speechConfig.js');
|
const config = require('../config/speechConfig.js');
|
||||||
const { database, username, password } = config.sql;
|
const { database, username, password } = config.sql;
|
||||||
|
|
|
@ -38,12 +38,8 @@ class ChannelCreateForm extends React.Component {
|
||||||
updateIsChannelAvailable (channel) {
|
updateIsChannelAvailable (channel) {
|
||||||
const channelWithAtSymbol = `@${channel}`;
|
const channelWithAtSymbol = `@${channel}`;
|
||||||
request(`/api/channel/availability/${channelWithAtSymbol}`)
|
request(`/api/channel/availability/${channelWithAtSymbol}`)
|
||||||
.then(isAvailable => {
|
.then(() => {
|
||||||
if (isAvailable) {
|
this.setState({'error': null});
|
||||||
this.setState({'error': null});
|
|
||||||
} else {
|
|
||||||
this.setState({'error': 'That channel has already been claimed'});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.setState({'error': error.message});
|
this.setState({'error': error.message});
|
||||||
|
@ -51,21 +47,9 @@ class ChannelCreateForm extends React.Component {
|
||||||
}
|
}
|
||||||
checkIsChannelAvailable (channel) {
|
checkIsChannelAvailable (channel) {
|
||||||
const channelWithAtSymbol = `@${channel}`;
|
const channelWithAtSymbol = `@${channel}`;
|
||||||
return new Promise((resolve, reject) => {
|
return request(`/api/channel/availability/${channelWithAtSymbol}`);
|
||||||
request(`/api/channel/availability/${channelWithAtSymbol}`)
|
|
||||||
.then(isAvailable => {
|
|
||||||
if (!isAvailable) {
|
|
||||||
return reject(new Error('That channel has already been claimed'));
|
|
||||||
}
|
|
||||||
resolve();
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
reject(error);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
checkIsPasswordProvided () {
|
checkIsPasswordProvided (password) {
|
||||||
const password = this.state.password;
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (!password || password.length < 1) {
|
if (!password || password.length < 1) {
|
||||||
return reject(new Error('Please provide a password'));
|
return reject(new Error('Please provide a password'));
|
||||||
|
@ -94,9 +78,9 @@ class ChannelCreateForm extends React.Component {
|
||||||
}
|
}
|
||||||
createChannel (event) {
|
createChannel (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.checkIsPasswordProvided()
|
this.checkIsPasswordProvided(this.state.password)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
return this.checkIsChannelAvailable(this.state.channel, this.state.password);
|
return this.checkIsChannelAvailable(this.state.channel);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.setState({status: 'We are publishing your new channel. Sit tight...'});
|
this.setState({status: 'We are publishing your new channel. Sit tight...'});
|
||||||
|
@ -107,7 +91,11 @@ class ChannelCreateForm extends React.Component {
|
||||||
this.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
this.props.onChannelLogin(result.channelName, result.shortChannelId, result.channelClaimId);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
this.setState({'error': error.message, status: null});
|
if (error.message) {
|
||||||
|
this.setState({'error': error.message, status: null});
|
||||||
|
} else {
|
||||||
|
this.setState({'error': error, status: null});
|
||||||
|
};
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
render () {
|
render () {
|
||||||
|
|
|
@ -16,14 +16,12 @@ const NO_CLAIM = 'NO_CLAIM';
|
||||||
|
|
||||||
module.exports = (app) => {
|
module.exports = (app) => {
|
||||||
// route to check whether site has published to a channel
|
// route to check whether site has published to a channel
|
||||||
app.get('/api/channel/availability/:name', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/channel/availability/:name', ({ ip, originalUrl, params: { name } }, res) => {
|
||||||
checkChannelAvailability(params.name)
|
const gaStartTime = Date.now();
|
||||||
.then(result => {
|
checkChannelAvailability(name)
|
||||||
if (result === true) {
|
.then(availableName => {
|
||||||
res.status(200).json(true);
|
res.status(200).json(availableName);
|
||||||
} else {
|
sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now());
|
||||||
res.status(200).json(false);
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleErrorResponse(originalUrl, ip, error, res);
|
errorHandlers.handleErrorResponse(originalUrl, ip, error, res);
|
||||||
|
@ -107,10 +105,12 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
// route to check whether this site published to a claim
|
// route to check whether this site published to a claim
|
||||||
app.get('/api/claim/availability/:name', ({ ip, originalUrl, params }, res) => {
|
app.get('/api/claim/availability/:name', ({ ip, originalUrl, params: { name } }, res) => {
|
||||||
claimNameIsAvailable(params.name)
|
const gaStartTime = Date.now();
|
||||||
|
claimNameIsAvailable(name)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
res.status(200).json(result);
|
res.status(200).json(result);
|
||||||
|
sendGATimingEvent('end-to-end', 'claim name availability', name, gaStartTime, Date.now());
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
errorHandlers.handleErrorResponse(originalUrl, ip, error, res);
|
errorHandlers.handleErrorResponse(originalUrl, ip, error, res);
|
||||||
|
@ -128,8 +128,6 @@ module.exports = (app) => {
|
||||||
});
|
});
|
||||||
// route to run a publish request on the daemon
|
// route to run a publish request on the daemon
|
||||||
app.post('/api/claim/publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl, user }, res) => {
|
app.post('/api/claim/publish', multipartMiddleware, ({ body, files, headers, ip, originalUrl, user }, res) => {
|
||||||
logger.debug('api/claim/publish req.body:', body);
|
|
||||||
logger.debug('api/claim/publish req.files:', files);
|
|
||||||
// define variables
|
// define variables
|
||||||
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title;
|
let channelName, channelId, channelPassword, description, fileName, filePath, fileType, gaStartTime, license, name, nsfw, thumbnail, thumbnailFileName, thumbnailFilePath, thumbnailFileType, title;
|
||||||
// record the start time of the request
|
// record the start time of the request
|
||||||
|
|
Loading…
Add table
Reference in a new issue