From 54bc80b08d95b70743881a6282cdb18265bd8267 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Tue, 5 Dec 2017 15:11:16 -0800 Subject: [PATCH] replaced channelId with channelClaimId --- models/certificate.js | 16 ++++++++-------- models/claim.js | 12 ++++++------ routes/serve-routes.js | 8 ++++---- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/models/certificate.js b/models/certificate.js index 01189262..6ab95374 100644 --- a/models/certificate.js +++ b/models/certificate.js @@ -123,14 +123,14 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => { }); }; - Certificate.getLongChannelIdFromShortChannelId = function (channelName, channelId) { + Certificate.getLongChannelIdFromShortChannelId = function (channelName, channelClaimId) { return new Promise((resolve, reject) => { this .findAll({ where: { name : channelName, claimId: { - $like: `${channelId}%`, + $like: `${channelClaimId}%`, }, }, order: [['height', 'ASC']], @@ -188,12 +188,12 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => { }); }; - Certificate.getLongChannelId = function (channelName, channelId) { - logger.debug(`getLongChannelId(${channelName}, ${channelId})`); - if (channelId && (channelId.length === 40)) { // if a full channel id is provided - return this.validateLongChannelId(channelName, channelId); - } else if (channelId && channelId.length < 40) { // if a short channel id is provided - return this.getLongChannelIdFromShortChannelId(channelName, channelId); + Certificate.getLongChannelId = function (channelName, channelClaimId) { + logger.debug(`getLongChannelId(${channelName}, ${channelClaimId})`); + if (channelClaimId && (channelClaimId.length === 40)) { // if a full channel id is provided + return this.validateLongChannelId(channelName, channelClaimId); + } else if (channelClaimId && channelClaimId.length < 40) { // if a short channel id is provided + return this.getLongChannelIdFromShortChannelId(channelName, channelClaimId); } else { return this.getLongChannelIdFromChannelName(channelName); // if no channel id provided } diff --git a/models/claim.js b/models/claim.js index 43181ec2..cbdf32be 100644 --- a/models/claim.js +++ b/models/claim.js @@ -180,12 +180,12 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => { }); }; - Claim.getAllChannelClaims = function (channelId) { - logger.debug(`Claim.getAllChannelClaims for ${channelId}`); + Claim.getAllChannelClaims = function (channelClaimId) { + logger.debug(`Claim.getAllChannelClaims for ${channelClaimId}`); return new Promise((resolve, reject) => { this .findAll({ - where: { certificateId: channelId }, + where: { certificateId: channelClaimId }, order: [['height', 'ASC']], }) .then(result => { @@ -202,12 +202,12 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => { }); }; - Claim.getClaimIdByLongChannelId = function (channelId, claimName) { - logger.debug(`finding claim id for claim ${claimName} from channel ${channelId}`); + Claim.getClaimIdByLongChannelId = function (channelClaimId, claimName) { + logger.debug(`finding claim id for claim ${claimName} from channel ${channelClaimId}`); return new Promise((resolve, reject) => { this .findAll({ - where: { name: claimName, certificateId: channelId }, + where: { name: claimName, certificateId: channelClaimId }, order: [['id', 'ASC']], }) .then(result => { diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 71421e04..42a6104b 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -245,24 +245,24 @@ function logRequestData (responseType, claimName, channelName, claimId) { module.exports = (app) => { // route to serve a specific asset using the channel or claim id app.get('/:identifier/:name', ({ headers, ip, originalUrl, params }, res) => { - let identifier = params.identifier; // '@channel', '@channel:channelId', or 'claimId' + let identifier = params.identifier; // '@channel', '@channel:channelClaimId', or 'claimId' let name = params.name; // 'example' or 'example.ext' [identifier, name] = flipClaimNameAndIdForBackwardsCompatibility(identifier, name); let channelName = null; let claimId = null; - let channelId = null; + let channelClaimId = null; let responseType = determineResponseType(name, headers); let claimName = determineName(name); if (isUriAChannel(identifier)) { channelName = returnChannelNameFromUri(identifier); - channelId = returnChannelIdFromUri(identifier); + channelClaimId = returnChannelIdFromUri(identifier); } else { claimId = identifier; } // log the request data for debugging logRequestData(responseType, claimName, channelName, claimId); // get the claim Id and then serve/show the asset - getClaimId(channelName, channelId, claimName, claimId) + getClaimId(channelName, channelClaimId, claimName, claimId) .then(fullClaimId => { if (fullClaimId === NO_CLAIM) { return res.status(200).render('noClaim');