Merge pull request #568 from lbryio/fix-no-channel-based-claim

updated Claim model to return proper error if no matching claim id found
This commit is contained in:
Bill Bittner 2018-08-08 11:41:43 -07:00 committed by GitHub
commit a26b1daa6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 19 deletions

View file

@ -36,7 +36,16 @@ const serverByIdentifierAndClaim = (req, res) => {
[claimId, claimName] = flipClaimNameAndId(claimId, claimName); [claimId, claimName] = flipClaimNameAndId(claimId, claimName);
} }
logger.debug('serve request:', { headers, ip, originalUrl, params }); logger.debug('serve request:', {
headers,
ip,
originalUrl,
params,
channelName,
channelClaimId,
claimName,
claimId,
});
getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res); getClaimIdAndServeAsset(channelName, channelClaimId, claimName, claimId, originalUrl, ip, res);

View file

@ -3,27 +3,19 @@ const logger = require('winston');
const db = require('../../models/index'); const db = require('../../models/index');
const getClaimIdByChannel = (channelName, channelClaimId, claimName) => { const getClaimIdByChannel = (channelName, channelClaimId, claimName) => {
return new Promise((resolve, reject) => { logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${claimName})`);
db.Certificate return db.Certificate
.getLongChannelId(channelName, channelClaimId) .getLongChannelId(channelName, channelClaimId)
.then(longChannelId => { .then(longChannelId => {
return db.Claim.getClaimIdByLongChannelId(longChannelId, claimName); return db.Claim.getClaimIdByLongChannelId(longChannelId, claimName);
}) });
.then(longClaimId => {
resolve(longClaimId);
})
.catch(error => {
reject(error);
});
});
}; };
const getClaimId = (channelName, channelClaimId, name, claimId) => { const getClaimId = (channelName, channelClaimId, name, claimId) => {
logger.debug(`getClaimId: ${channelName}, ${channelClaimId}, ${name}, ${claimId})`);
if (channelName) { if (channelName) {
logger.debug(`getClaimIdByChannel(${channelName}, ${channelClaimId}, ${name})`);
return getClaimIdByChannel(channelName, channelClaimId, name); return getClaimIdByChannel(channelName, channelClaimId, name);
} else { } else {
logger.debug(`db.Claim.getLongClaimId(${name}, ${claimId})`);
return db.Claim.getLongClaimId(name, claimId); return db.Claim.getLongClaimId(name, claimId);
} }
}; };

View file

@ -260,11 +260,11 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
.then(result => { .then(result => {
switch (result.length) { switch (result.length) {
case 0: case 0:
return resolve(null); return reject(NO_CLAIM);
case 1: case 1:
return resolve(result[0].claimId); return resolve(result[0].claimId);
default: default:
logger.error(`${result.length} records found for "${claimName}" in channel "${channelClaimId}"`); logger.warn(`${result.length} records found for "${claimName}" in channel "${channelClaimId}"`);
return resolve(result[0].claimId); return resolve(result[0].claimId);
} }
}) })
@ -344,7 +344,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
}; };
Claim.getLongClaimId = function (claimName, claimId) { Claim.getLongClaimId = function (claimName, claimId) {
// logger.debug(`getLongClaimId(${claimName}, ${claimId})`); logger.debug(`getLongClaimId(${claimName}, ${claimId})`);
if (isLongClaimId(claimId)) { if (isLongClaimId(claimId)) {
return this.validateLongClaimId(claimName, claimId); return this.validateLongClaimId(claimName, claimId);
} else if (isShortClaimId(claimId)) { } else if (isShortClaimId(claimId)) {
@ -379,6 +379,7 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
}; };
Claim.getOutpoint = function (name, claimId) { Claim.getOutpoint = function (name, claimId) {
logger.debug(`finding outpoint for ${name}#${claimId}`);
return this return this
.findAll({ .findAll({
where : { name, claimId }, where : { name, claimId },