diff --git a/controllers/serveController.js b/controllers/serveController.js index 4017bd33..b83b68e7 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -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 => { diff --git a/controllers/statsController.js b/controllers/statsController.js index 0e736d66..0cd3da95 100644 --- a/controllers/statsController.js +++ b/controllers/statsController.js @@ -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(); diff --git a/helpers/functions/getAllFreePublicClaims.js b/helpers/functions/getAllFreePublicClaims.js index 0f9c30a2..b498bd09 100644 --- a/helpers/functions/getAllFreePublicClaims.js +++ b/helpers/functions/getAllFreePublicClaims.js @@ -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; } diff --git a/helpers/libraries/lbryApi.js b/helpers/libraries/lbryApi.js index 026e1eee..b240b6c5 100644 --- a/helpers/libraries/lbryApi.js +++ b/helpers/libraries/lbryApi.js @@ -78,7 +78,7 @@ module.exports = { reject(data.result[uri].error); return; } - resolve(data.result); + resolve(data.result[uri]); }) .catch(error => { reject(error);