added new db field and search to compare speech addresses on potential hits
This commit is contained in:
parent
c3b679636d
commit
db318bbac3
9 changed files with 73 additions and 22 deletions
|
@ -20,19 +20,20 @@ function upsert (Model, values, condition) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
publish: (publishParams, fileName, fileType) => {
|
||||
publish (publishParams, fileName, fileType) {
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
// 1. publish the file
|
||||
lbryApi
|
||||
.publishClaim(publishParams)
|
||||
.then(result => {
|
||||
logger.info(`Successfully published ${fileName}`, result);
|
||||
// 2. update old record of create new one (update is in case the claim has been published before by this daemon)
|
||||
// 2. update old record or create new one (update is in case the claim has been published before by this daemon)
|
||||
upsert(
|
||||
db.File,
|
||||
{
|
||||
name : publishParams.name,
|
||||
claimId : result.claim_id,
|
||||
address : publishParams.claim_address,
|
||||
outpoint: `${result.txid}:${result.nout}`,
|
||||
height : 0,
|
||||
fileName,
|
||||
|
@ -63,13 +64,32 @@ module.exports = {
|
|||
});
|
||||
return deferred;
|
||||
},
|
||||
checkNameAvailability: (name) => {
|
||||
checkNameAvailability (name) {
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
// find any records where the name is used
|
||||
db.File
|
||||
.findAll({ where: { name } })
|
||||
.then(result => {
|
||||
resolve(result);
|
||||
if (result.length >= 1) {
|
||||
// filter out any results that were not published from a spee.ch wallet address
|
||||
lbryApi
|
||||
.getWalletList()
|
||||
.then((walletList) => {
|
||||
const filteredResult = result.filter((claim) => {
|
||||
return walletList.includes(claim.address);
|
||||
});
|
||||
if (filteredResult.length >= 1) {
|
||||
resolve(false);
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
reject(error);
|
||||
});
|
||||
} else {
|
||||
resolve(true);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
|
|
|
@ -18,6 +18,7 @@ function updateFileIfNeeded (uri, claimName, claimId, localOutpoint, localHeight
|
|||
// logger.debug('resolved result:', result);
|
||||
const resolvedOutpoint = `${result.claim.txid}:${result.claim.nout}`;
|
||||
const resolvedHeight = result.claim.height;
|
||||
const resolvedAddress = result.claim.address;
|
||||
logger.debug('database outpoint:', localOutpoint);
|
||||
logger.debug('resolved outpoint:', resolvedOutpoint);
|
||||
// 2. if the outpoint's match, no further work needed
|
||||
|
@ -29,7 +30,7 @@ function updateFileIfNeeded (uri, claimName, claimId, localOutpoint, localHeight
|
|||
// 2. get the resolved claim
|
||||
} else {
|
||||
logger.debug(`local outpoint did not match for ${uri}. Initiating update.`);
|
||||
getClaimAndUpdate(uri, resolvedHeight);
|
||||
getClaimAndUpdate(uri, resolvedAddress, resolvedHeight);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -37,7 +38,7 @@ function updateFileIfNeeded (uri, claimName, claimId, localOutpoint, localHeight
|
|||
});
|
||||
}
|
||||
|
||||
function getClaimAndUpdate (uri, height) {
|
||||
function getClaimAndUpdate (uri, address, height) {
|
||||
// 1. get the claim
|
||||
lbryApi
|
||||
.getClaim(uri)
|
||||
|
@ -47,7 +48,8 @@ function getClaimAndUpdate (uri, height) {
|
|||
db.File
|
||||
.update({
|
||||
outpoint,
|
||||
height, // note: height is coming from 'resolve', not 'get'.
|
||||
height, // note: height is coming from the 'resolve', not 'get'.
|
||||
address, // note: address is coming from the 'resolve', not 'get'.
|
||||
fileName: file_name,
|
||||
filePath: download_path,
|
||||
fileType: mime_type,
|
||||
|
@ -70,7 +72,7 @@ function getClaimAndUpdate (uri, height) {
|
|||
});
|
||||
}
|
||||
|
||||
function getClaimAndHandleResponse (uri, height, resolve, reject) {
|
||||
function getClaimAndHandleResponse (uri, address, height, resolve, reject) {
|
||||
lbryApi
|
||||
.getClaim(uri)
|
||||
.then(({ name, claim_id, outpoint, file_name, download_path, mime_type, metadata }) => {
|
||||
|
@ -80,8 +82,9 @@ function getClaimAndHandleResponse (uri, height, resolve, reject) {
|
|||
.create({
|
||||
name,
|
||||
claimId : claim_id,
|
||||
address, // note: comes from parent 'resolve,' not this 'get' call
|
||||
outpoint,
|
||||
height,
|
||||
height, // note: comes from parent 'resolve,' not this 'get' call
|
||||
fileName: file_name,
|
||||
filePath: download_path,
|
||||
fileType: mime_type,
|
||||
|
@ -120,6 +123,7 @@ module.exports = {
|
|||
const claimId = freePublicClaimList[0].claim_id;
|
||||
const uri = `${name}#${claimId}`;
|
||||
const height = freePublicClaimList[0].height;
|
||||
const address = freePublicClaimList[0].address;
|
||||
// 2. check to see if the file is available locally
|
||||
db.File
|
||||
.findOne({ where: { name, claimId } })
|
||||
|
@ -133,7 +137,7 @@ module.exports = {
|
|||
// 3. otherwise use daemon to retrieve it
|
||||
} else {
|
||||
// get the claim and serve it
|
||||
getClaimAndHandleResponse(uri, height, resolve, reject);
|
||||
getClaimAndHandleResponse(uri, address, height, resolve, reject);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
@ -175,7 +179,7 @@ module.exports = {
|
|||
// 4. check to see if the claim is free & public
|
||||
if (isFreePublicClaim(result.claim)) {
|
||||
// 5. get claim and serve
|
||||
getClaimAndHandleResponse(uri, result.claim.height, resolve, reject);
|
||||
getClaimAndHandleResponse(uri, result.claim.address, result.claim.height, resolve, reject);
|
||||
} else {
|
||||
reject(null);
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ const db = require('../models');
|
|||
const googleApiKey = config.get('AnalyticsConfig.GoogleId');
|
||||
|
||||
module.exports = {
|
||||
postToStats: (action, url, ipAddress, result) => {
|
||||
postToStats (action, url, ipAddress, result) {
|
||||
logger.silly(`creating ${action} record for statistics db`);
|
||||
// make sure the result is a string
|
||||
if (result && (typeof result !== 'string')) {
|
||||
|
@ -27,7 +27,7 @@ module.exports = {
|
|||
logger.error('sequelize error', error);
|
||||
});
|
||||
},
|
||||
sendGoogleAnalytics: (action, ip, originalUrl) => {
|
||||
sendGoogleAnalytics (action, ip, originalUrl) {
|
||||
const visitorId = ip.replace(/\./g, '-');
|
||||
const visitor = ua(googleApiKey, visitorId, { strictCidFormat: false, https: true });
|
||||
switch (action) {
|
||||
|
@ -55,7 +55,7 @@ module.exports = {
|
|||
default: break;
|
||||
}
|
||||
},
|
||||
getStatsSummary: () => {
|
||||
getStatsSummary () {
|
||||
logger.debug('retrieving site statistics');
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
// get the raw statistics data
|
||||
|
|
|
@ -28,7 +28,7 @@ function orderClaims (claimsListArray) {
|
|||
return claimsListArray;
|
||||
}
|
||||
|
||||
module.exports = claimName => {
|
||||
module.exports = (claimName) => {
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
// make a call to the daemon to get the claims list
|
||||
lbryApi
|
||||
|
|
|
@ -2,6 +2,23 @@ const axios = require('axios');
|
|||
const logger = require('winston');
|
||||
|
||||
module.exports = {
|
||||
getWalletList () {
|
||||
logger.debug('getting wallet list');
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
axios
|
||||
.post('http://localhost:5279/lbryapi', {
|
||||
method: 'wallet_list',
|
||||
})
|
||||
.then(response => {
|
||||
const result = response.data.result;
|
||||
resolve(result);
|
||||
})
|
||||
.catch(error => {
|
||||
reject(error);
|
||||
});
|
||||
});
|
||||
return deferred;
|
||||
},
|
||||
publishClaim (publishParams) {
|
||||
logger.debug(`Publishing claim to "${publishParams.name}"`);
|
||||
const deferred = new Promise((resolve, reject) => {
|
||||
|
|
|
@ -3,7 +3,7 @@ const config = require('config');
|
|||
const fs = require('fs');
|
||||
|
||||
module.exports = {
|
||||
createPublishParams: (name, filePath, license, nsfw) => {
|
||||
createPublishParams (name, filePath, license, nsfw) {
|
||||
logger.debug(`Creating Publish Parameters for "${name}"`);
|
||||
// const payAddress = config.get('WalletConfig.LbryPayAddress');
|
||||
const claimAddress = config.get('WalletConfig.LbryClaimAddress');
|
||||
|
@ -40,7 +40,7 @@ module.exports = {
|
|||
logger.debug('publishParams:', publishParams);
|
||||
return publishParams;
|
||||
},
|
||||
deleteTemporaryFile: (filePath) => {
|
||||
deleteTemporaryFile (filePath) {
|
||||
fs.unlink(filePath, err => {
|
||||
if (err) throw err;
|
||||
logger.debug(`successfully deleted ${filePath}`);
|
||||
|
|
|
@ -10,6 +10,10 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER }) => {
|
|||
type : STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
address: {
|
||||
type : STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
outpoint: {
|
||||
type : STRING,
|
||||
allowNull: false,
|
||||
|
|
|
@ -118,8 +118,13 @@ document.getElementById('publish-submit').addEventListener('click', function(eve
|
|||
xhttp.onreadystatechange = function() {
|
||||
if (this.readyState == 4 ) {
|
||||
if ( this.status == 200) {
|
||||
console.log(this.response);
|
||||
if (this.response == true) {
|
||||
console.log(true);
|
||||
//uploader.submitFiles(stagedFiles);
|
||||
} else {
|
||||
alert("That name has already been claimed by spee.ch. Please choose a different name.");
|
||||
}
|
||||
|
||||
} else {
|
||||
console.log("request to check claim name failed with status:", this.status);
|
||||
};
|
||||
|
|
|
@ -33,10 +33,11 @@ module.exports = app => {
|
|||
publishController
|
||||
.checkNameAvailability(params.name)
|
||||
.then(result => {
|
||||
if (result.length >= 1) {
|
||||
res.status(200).json(false);
|
||||
} else {
|
||||
if (result === true) {
|
||||
res.status(200).json(true);
|
||||
} else {
|
||||
logger.debug(`Rejecting publish request because ${params.name} has already been published via spee.ch`);
|
||||
res.status(200).json(false);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
|
|
Loading…
Reference in a new issue