From e7eb930231160be829d150661ee7a4b671099103 Mon Sep 17 00:00:00 2001 From: bill bittner Date: Thu, 7 Dec 2017 09:28:44 -0800 Subject: [PATCH] fixed channel page view --- controllers/serveController.js | 18 ++---------------- helpers/lbryuri.js | 13 +++++++------ models/claim.js | 2 ++ routes/serve-routes.js | 14 +++++++------- views/channel.handlebars | 14 +++++++------- views/partials/gridItem.handlebars | 6 +++--- 6 files changed, 28 insertions(+), 39 deletions(-) diff --git a/controllers/serveController.js b/controllers/serveController.js index 19579be0..5176a80b 100644 --- a/controllers/serveController.js +++ b/controllers/serveController.js @@ -5,14 +5,6 @@ const NO_CHANNEL = 'NO_CHANNEL'; const NO_CLAIM = 'NO_CLAIM'; const NO_FILE = 'NO_FILE'; -function addUrlInformation (claim, channelName, longChannelClaimId, shortChannelClaimId, name, fileExtension) { - claim['showUrlLong'] = `/${channelName}:${longChannelClaimId}/${name}`; - claim['directUrlLong'] = `/${channelName}:${longChannelClaimId}/${name}.${fileExtension}`; - claim['showUrlShort'] = `/${channelName}:${shortChannelClaimId}/${name}`; - claim['directUrlShort'] = `/${channelName}:${shortChannelClaimId}/${name}.${fileExtension}`; - return claim; -} - module.exports = { getClaimId (channelName, channelClaimId, name, claimId) { if (channelName) { @@ -60,7 +52,7 @@ module.exports = { }); }); }, - getChannelInfoAndContent (channelName, channelClaimId) { // note: move down to model layer? + getChannelInfoAndClaims (channelName, channelClaimId) { return new Promise((resolve, reject) => { // 1. get the long channel Id (make sure channel exists) db.Certificate.getLongChannelId(channelName, channelClaimId) @@ -75,13 +67,7 @@ module.exports = { if (!longChannelClaimId) { return resolve(NO_CHANNEL); } - // 3. add url information to each claim - if (channelClaimsArray) { - channelClaimsArray.forEach(claim => { - return addUrlInformation(claim); - }); - } - // 4. return all the channel information and contents + // 3. return all the channel information and contents resolve({ channelName, longChannelClaimId, shortChannelClaimId, claims: channelClaimsArray }); }) .catch(error => { diff --git a/helpers/lbryuri.js b/helpers/lbryuri.js index 254f1607..0f178c84 100644 --- a/helpers/lbryuri.js +++ b/helpers/lbryuri.js @@ -2,10 +2,11 @@ const logger = require('winston'); // const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js'); module.exports = { - REGEXP_INVALID_URI: /[^A-Za-z0-9-]/g, - REGEXP_ADDRESS : /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/, - CHANNEL_CHAR : '@', - parseIdentifier : function (identifier) { + REGEXP_INVALID_CLAIM : /[^A-Za-z0-9-]/g, + REGEXP_INVALID_CHANNEL: /[^A-Za-z0-9-@]/g, + REGEXP_ADDRESS : /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/, + CHANNEL_CHAR : '@', + parseIdentifier : function (identifier) { logger.debug('parsing identifier:', identifier); const componentsRegex = new RegExp( '([^:$#/]*)' + // value (stops at the first separator or end) @@ -24,7 +25,7 @@ module.exports = { if (!channelName) { throw new Error('No channel name after @.'); } - const nameBadChars = (channelName).match(module.exports.REGEXP_INVALID_URI); + const nameBadChars = (channelName).match(module.exports.REGEXP_INVALID_CHANNEL); if (nameBadChars) { throw new Error(`Invalid characters in channel name: ${nameBadChars.join(', ')}.`); } @@ -67,7 +68,7 @@ module.exports = { if (!claimName) { throw new Error('No claim name provided before .'); } - const nameBadChars = (claimName).match(module.exports.REGEXP_INVALID_URI); + const nameBadChars = (claimName).match(module.exports.REGEXP_INVALID_CLAIM); if (nameBadChars) { throw new Error(`Invalid characters in claim name: ${nameBadChars.join(', ')}.`); } diff --git a/models/claim.js b/models/claim.js index 6e32e135..090bbaa2 100644 --- a/models/claim.js +++ b/models/claim.js @@ -268,8 +268,10 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => { .findAll({ where: { certificateId: channelClaimId }, order: [['height', 'ASC']], + raw : true, // returns an array of only data, not an array of instances }) .then(channelClaimsArray => { + // logger.debug('channelclaimsarray length:', channelClaimsArray.length); switch (channelClaimsArray.length) { case 0: return resolve(null); diff --git a/routes/serve-routes.js b/routes/serve-routes.js index 5f8480b5..60ec0f5a 100644 --- a/routes/serve-routes.js +++ b/routes/serve-routes.js @@ -1,5 +1,5 @@ const logger = require('winston'); -const { getClaimId, getChannelInfoAndContent, getLocalFileRecord } = require('../controllers/serveController.js'); +const { getClaimId, getChannelInfoAndClaims, getLocalFileRecord } = require('../controllers/serveController.js'); const serveHelpers = require('../helpers/serveHelpers.js'); const { handleRequestError } = require('../helpers/errorHandlers.js'); const db = require('../models'); @@ -100,20 +100,20 @@ function returnOptionsForChannelPageRendering (result, query) { return options; } -function sendChannelInfoAndContentToClient (result, query, res) { - if (result === NO_CHANNEL) { // (a) no channel found +function sendChannelInfoAndContentToClient (channelInfoAndClaims, query, res) { + if (channelInfoAndClaims === NO_CHANNEL) { // (a) no channel found res.status(200).render('noChannel'); } else { // (b) channel found - const options = returnOptionsForChannelPageRendering(result, query); + const options = returnOptionsForChannelPageRendering(channelInfoAndClaims, query); res.status(200).render('channel', options); } } function showChannelPageToClient (channelName, channelClaimId, originalUrl, ip, query, res) { // 1. retrieve the channel contents - getChannelInfoAndContent(channelName, channelClaimId) - .then(result => { - sendChannelInfoAndContentToClient(result, query, res); + getChannelInfoAndClaims(channelName, channelClaimId) + .then(channelInfoAndClaims => { + sendChannelInfoAndContentToClient(channelInfoAndClaims, query, res); }) .catch(error => { handleRequestError(originalUrl, ip, error, res); diff --git a/views/channel.handlebars b/views/channel.handlebars index d512e675..37eee568 100644 --- a/views/channel.handlebars +++ b/views/channel.handlebars @@ -1,10 +1,10 @@
{{#ifConditional this.totalPages '===' 0}} -

There is no content in {{this.channelName}}:{{this.longChannelId}} yet. Upload some!

+

There is no content in {{this.channelName}}:{{this.longChannelClaimId}} yet. Upload some!

{{/ifConditional}} {{#ifConditional this.totalPages '>=' 1}} -

Below are the contents for {{this.channelName}}:{{this.longChannelId}}

+

Below are the contents for {{this.channelName}}:{{this.longChannelClaimId}}

{{#each this.claims}} {{> gridItem}} @@ -14,21 +14,21 @@ {{#ifConditional this.totalPages '>' 1}}
{{#if this.previousPage}} - Previous + Previous {{else}} Previous {{/if}} | {{#if this.nextPage}} - Next + Next {{else}} Next {{/if}}
{{/ifConditional}} @@ -51,4 +51,4 @@ }); - \ No newline at end of file + diff --git a/views/partials/gridItem.handlebars b/views/partials/gridItem.handlebars index 4ffa06c2..3199a996 100644 --- a/views/partials/gridItem.handlebars +++ b/views/partials/gridItem.handlebars @@ -2,11 +2,11 @@ {{#ifConditional this.contentType '===' 'video/mp4'}} {{else}} - + {{/ifConditional}} - \ No newline at end of file +