From ab14adca002bd677d3662c902097f6415edc120b Mon Sep 17 00:00:00 2001 From: bill bittner Date: Wed, 18 Oct 2017 11:16:07 -0700 Subject: [PATCH] fixed substring issue and added no claim/no channel pages --- controllers/serveController.js | 5 +++-- models/index.js | 3 ++- routes/serve-routes.js | 18 ++++++++++-------- views/noChannel.handlebars | 8 ++++---- ...{noClaims.handlebars => noClaim.handlebars} | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) rename views/{noClaims.handlebars => noClaim.handlebars} (90%) diff --git a/controllers/serveController.js b/controllers/serveController.js index 50403a16..c6d9be90 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -108,15 +108,16 @@ function chooseThumbnail (claimInfo, defaultThumbnail) { module.exports = { getAssetByClaim (claimName, claimId) { - logger.debug('getting asset by claim'); + logger.debug(`getAssetByClaim(${claimName}, ${claimId})`); return new Promise((resolve, reject) => { db.getLongClaimId(claimName, claimId) // 1. get the long claim id .then(result => { // 2. get the asset using the long claim id + logger.debug('getLongClaimId result:', result); if (result === NO_CLAIM) { + logger.debug('resolving NO_CLAIM'); resolve(NO_CLAIM); return; } - logger.debug('long claim id = ', result); resolve(getAssetByLongClaimId(result, claimName)); }) .catch(error => { diff --git a/models/index.js b/models/index.js index 192cece9..687b4a2a 100644 --- a/models/index.js +++ b/models/index.js @@ -71,6 +71,7 @@ function getTopFreeClaimIdByClaimName (name) { db .sequelize.query(`SELECT claimId FROM Claim WHERE name = '${name}' ORDER BY effectiveAmount DESC, height ASC LIMIT 1`, { type: db.sequelize.QueryTypes.SELECT }) .then(result => { + logger.debug('getTopFreeClaimIdByClaimName result:', result); switch (result.length) { case 0: return resolve(NO_CLAIM); @@ -290,7 +291,7 @@ db['getAllChannelClaims'] = (channelId) => { }; db['getLongClaimId'] = (claimName, claimId) => { - logger.debug(`getLongClaimId (${claimName}, ${claimId})`); + logger.debug(`getLongClaimId(${claimName}, ${claimId})`); if (claimId && (claimId.length === 40)) { // if a full claim id is provided return new Promise((resolve, reject) => resolve(claimId)); } else if (claimId && claimId.length < 40) { diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 02e66555..f8dc04ca 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -142,11 +142,12 @@ module.exports = (app) => { getAsset(claimOrChannel, channelName, channelId, name, claimId) // 2. serve or show .then(result => { - if (!result || result === NO_CLAIM) { - res.status(200).json({success: true, message: 'no matching claims were found'}); + logger.debug('getAsset result:', result); + if (result === NO_CLAIM) { + res.status(200).render('noClaim'); return; } else if (result === NO_CHANNEL) { - res.status(200).json({success: true, message: 'no matching channel was found'}); + res.status(200).render('noChannel'); return; } return serveOrShowAsset(result, fileExtension, method, headers, originalUrl, ip, res); @@ -183,7 +184,7 @@ module.exports = (app) => { // 2. respond to the request .then(result => { if (result === NO_CHANNEL) { // no channel found - res.status(200).json({ success: true, message: 'no matching channel found' }); + res.status(200).render('noChannel'); } else if (!result.claims) { // channel found, but no claims res.status(200).render('channel', { channelName : result.channelName, @@ -235,11 +236,12 @@ module.exports = (app) => { // 1. retrieve the asset and information getAsset(CLAIM, null, null, name, null) // 2. respond to the request - .then(fileInfo => { - if (!fileInfo) { - res.status(200).render('noClaims'); + .then(result => { + logger.debug('getAsset result', result); + if (result === NO_CLAIM) { + res.status(200).render('noClaim'); } else { - return serveOrShowAsset(fileInfo, fileExtension, method, headers, originalUrl, ip, res); + return serveOrShowAsset(result, fileExtension, method, headers, originalUrl, ip, res); } }) // 3. update the database diff --git a/views/noChannel.handlebars b/views/noChannel.handlebars index 103e3f0b..b1e112ed 100644 --- a/views/noChannel.handlebars +++ b/views/noChannel.handlebars @@ -1,5 +1,5 @@ -
-

No Claims

-

There are no free assets on this channel.

-

If you think this message is an error, contact us in the LBRY slack!

+
+

[No Channel]

+

There are no published channels matching your url

+

If you think this message is an error, contact us in the LBRY slack!

diff --git a/views/noClaims.handlebars b/views/noClaim.handlebars similarity index 90% rename from views/noClaims.handlebars rename to views/noClaim.handlebars index c68c1cb5..9277e13e 100644 --- a/views/noClaims.handlebars +++ b/views/noClaim.handlebars @@ -1,5 +1,5 @@
-

No Claims

+

[No Claims]

There are no free assets at that claim. You should publish one at spee.ch.

NOTE: it is possible your claim was published, but it is still being processed by the blockchain