Dealing with lack of claims as a success #64

Merged
bones7242 merged 2 commits from no-claims-found into master 2017-07-01 00:47:19 +02:00
4 changed files with 21 additions and 11 deletions
Showing only changes of commit f7baf5aac1 - Show all commits

View file

@ -5,15 +5,19 @@ const getAllFreePublicClaims = require('../helpers/functions/getAllFreePublicCla
const isFreePublicClaim = require('../helpers/functions/isFreePublicClaim.js');
function updateFileIfNeeded (uri, claimName, claimId, localOutpoint, localHeight) {
logger.debug(`A mysql record was found for ${claimId}`);
logger.debug('initiating resolve on claim to check outpoint');
logger.debug(`A mysql record was found for ${claimName}:${claimId}. Initiating resolve to check outpoint.`);
// 1. resolve claim
lbryApi
.resolveUri(uri)
.then(result => {
// check to make sure the result is a claim
if (!result.claim) {
logger.debug('resolve did not return a claim');
return;
}
// logger.debug('resolved result:', result);
const resolvedOutpoint = `${result[uri].claim.txid}:${result[uri].claim.nout}`;
const resolvedHeight = result[uri].claim.height;
const resolvedOutpoint = `${result.claim.txid}:${result.claim.nout}`;
const resolvedHeight = result.claim.height;
logger.debug('database outpoint:', localOutpoint);
logger.debug('resolved outpoint:', resolvedOutpoint);
// 2. if the outpoint's match, no further work needed
@ -157,12 +161,18 @@ module.exports = {
lbryApi
.resolveUri(uri)
.then(result => {
// check to make sure the result is a claim
if (!result.claim) {
logger.debug('resolve did not return a claim');
reject('NO_FREE_PUBLIC_CLAIMS'); // note: should be a resolve not a reject! but I need routes to handle that properly. right now it is handled as an error.
return;
}
// 4. check to see if the claim is free & public
if (isFreePublicClaim(result[uri].claim)) {
if (isFreePublicClaim(result.claim)) {
// 5. get claim and serve
getClaimAndHandleResponse(uri, result[uri].claim.height, resolve, reject);
getClaimAndHandleResponse(uri, result.claim.height, resolve, reject);
} else {
reject('NO_FREE_PUBLIC_CLAIMS');
reject('NO_FREE_PUBLIC_CLAIMS'); // note: should be a resolve not a reject! but I need routes to handle that properly. right now it is handled as an error.
}
})
.catch(error => {

View file

@ -6,7 +6,7 @@ const googleApiKey = config.get('AnalyticsConfig.GoogleId');
module.exports = {
postToStats: (action, url, ipAddress, result) => {
logger.silly('creating record for statistics db');
logger.silly(`creating ${action} record for statistics db`);
// make sure the result is a string
if (result && (typeof result !== 'string')) {
result = result.toString();

View file

@ -38,7 +38,7 @@ module.exports = claimName => {
logger.debug(`Number of claims: ${claimsList.length}`);
// return early if no claims were found
if (claimsList.length === 0) {
reject('NO_CLAIMS');
reject('NO_CLAIMS'); // note: should be a resolve not a reject! but I need routes to handle that properly. right now it is handled as an error.
logger.debug('exiting due to lack of claims');
return;
}
@ -46,7 +46,7 @@ module.exports = claimName => {
const freePublicClaims = filterForFreePublicClaims(claimsList);
// return early if no free, public claims were found
if (!freePublicClaims || freePublicClaims.length === 0) {
reject('NO_FREE_PUBLIC_CLAIMS');
reject('NO_FREE_PUBLIC_CLAIMS'); // note: should be a resolve not a reject! but I need routes to handle that properly. right now it is handled as an error.
logger.debug('exiting due to lack of free or public claims');
return;
}

View file

@ -78,7 +78,7 @@ module.exports = {
reject(data.result[uri].error);
return;
}
resolve(data.result);
resolve(data.result[uri]);
})
.catch(error => {
reject(error);