fixed channel page view

This commit is contained in:
bill bittner 2017-12-07 09:28:44 -08:00
parent 075332275e
commit e7eb930231
6 changed files with 28 additions and 39 deletions

View file

@ -5,14 +5,6 @@ const NO_CHANNEL = 'NO_CHANNEL';
const NO_CLAIM = 'NO_CLAIM'; const NO_CLAIM = 'NO_CLAIM';
const NO_FILE = 'NO_FILE'; 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 = { module.exports = {
getClaimId (channelName, channelClaimId, name, claimId) { getClaimId (channelName, channelClaimId, name, claimId) {
if (channelName) { 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) => { return new Promise((resolve, reject) => {
// 1. get the long channel Id (make sure channel exists) // 1. get the long channel Id (make sure channel exists)
db.Certificate.getLongChannelId(channelName, channelClaimId) db.Certificate.getLongChannelId(channelName, channelClaimId)
@ -75,13 +67,7 @@ module.exports = {
if (!longChannelClaimId) { if (!longChannelClaimId) {
return resolve(NO_CHANNEL); return resolve(NO_CHANNEL);
} }
// 3. add url information to each claim // 3. return all the channel information and contents
if (channelClaimsArray) {
channelClaimsArray.forEach(claim => {
return addUrlInformation(claim);
});
}
// 4. return all the channel information and contents
resolve({ channelName, longChannelClaimId, shortChannelClaimId, claims: channelClaimsArray }); resolve({ channelName, longChannelClaimId, shortChannelClaimId, claims: channelClaimsArray });
}) })
.catch(error => { .catch(error => {

View file

@ -2,10 +2,11 @@ const logger = require('winston');
// const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js'); // const { postToStats, sendGoogleAnalytics } = require('../controllers/statsController.js');
module.exports = { module.exports = {
REGEXP_INVALID_URI: /[^A-Za-z0-9-]/g, REGEXP_INVALID_CLAIM : /[^A-Za-z0-9-]/g,
REGEXP_ADDRESS : /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/, REGEXP_INVALID_CHANNEL: /[^A-Za-z0-9-@]/g,
CHANNEL_CHAR : '@', REGEXP_ADDRESS : /^b(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$/,
parseIdentifier : function (identifier) { CHANNEL_CHAR : '@',
parseIdentifier : function (identifier) {
logger.debug('parsing identifier:', identifier); logger.debug('parsing identifier:', identifier);
const componentsRegex = new RegExp( const componentsRegex = new RegExp(
'([^:$#/]*)' + // value (stops at the first separator or end) '([^:$#/]*)' + // value (stops at the first separator or end)
@ -24,7 +25,7 @@ module.exports = {
if (!channelName) { if (!channelName) {
throw new Error('No channel name after @.'); 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) { if (nameBadChars) {
throw new Error(`Invalid characters in channel name: ${nameBadChars.join(', ')}.`); throw new Error(`Invalid characters in channel name: ${nameBadChars.join(', ')}.`);
} }
@ -67,7 +68,7 @@ module.exports = {
if (!claimName) { if (!claimName) {
throw new Error('No claim name provided before .'); 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) { if (nameBadChars) {
throw new Error(`Invalid characters in claim name: ${nameBadChars.join(', ')}.`); throw new Error(`Invalid characters in claim name: ${nameBadChars.join(', ')}.`);
} }

View file

@ -268,8 +268,10 @@ module.exports = (sequelize, { STRING, BOOLEAN, INTEGER, TEXT, DECIMAL }) => {
.findAll({ .findAll({
where: { certificateId: channelClaimId }, where: { certificateId: channelClaimId },
order: [['height', 'ASC']], order: [['height', 'ASC']],
raw : true, // returns an array of only data, not an array of instances
}) })
.then(channelClaimsArray => { .then(channelClaimsArray => {
// logger.debug('channelclaimsarray length:', channelClaimsArray.length);
switch (channelClaimsArray.length) { switch (channelClaimsArray.length) {
case 0: case 0:
return resolve(null); return resolve(null);

View file

@ -1,5 +1,5 @@
const logger = require('winston'); 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 serveHelpers = require('../helpers/serveHelpers.js');
const { handleRequestError } = require('../helpers/errorHandlers.js'); const { handleRequestError } = require('../helpers/errorHandlers.js');
const db = require('../models'); const db = require('../models');
@ -100,20 +100,20 @@ function returnOptionsForChannelPageRendering (result, query) {
return options; return options;
} }
function sendChannelInfoAndContentToClient (result, query, res) { function sendChannelInfoAndContentToClient (channelInfoAndClaims, query, res) {
if (result === NO_CHANNEL) { // (a) no channel found if (channelInfoAndClaims === NO_CHANNEL) { // (a) no channel found
res.status(200).render('noChannel'); res.status(200).render('noChannel');
} else { // (b) channel found } else { // (b) channel found
const options = returnOptionsForChannelPageRendering(result, query); const options = returnOptionsForChannelPageRendering(channelInfoAndClaims, query);
res.status(200).render('channel', options); res.status(200).render('channel', options);
} }
} }
function showChannelPageToClient (channelName, channelClaimId, originalUrl, ip, query, res) { function showChannelPageToClient (channelName, channelClaimId, originalUrl, ip, query, res) {
// 1. retrieve the channel contents // 1. retrieve the channel contents
getChannelInfoAndContent(channelName, channelClaimId) getChannelInfoAndClaims(channelName, channelClaimId)
.then(result => { .then(channelInfoAndClaims => {
sendChannelInfoAndContentToClient(result, query, res); sendChannelInfoAndContentToClient(channelInfoAndClaims, query, res);
}) })
.catch(error => { .catch(error => {
handleRequestError(originalUrl, ip, error, res); handleRequestError(originalUrl, ip, error, res);

View file

@ -1,10 +1,10 @@
<div class="row row--padded"> <div class="row row--padded">
<div class="row"> <div class="row">
{{#ifConditional this.totalPages '===' 0}} {{#ifConditional this.totalPages '===' 0}}
<p>There is no content in {{this.channelName}}:{{this.longChannelId}} yet. Upload some!</p> <p>There is no content in {{this.channelName}}:{{this.longChannelClaimId}} yet. Upload some!</p>
{{/ifConditional}} {{/ifConditional}}
{{#ifConditional this.totalPages '>=' 1}} {{#ifConditional this.totalPages '>=' 1}}
<p>Below are the contents for {{this.channelName}}:{{this.longChannelId}}</p> <p>Below are the contents for {{this.channelName}}:{{this.longChannelClaimId}}</p>
<div class="grid"> <div class="grid">
{{#each this.claims}} {{#each this.claims}}
{{> gridItem}} {{> gridItem}}
@ -14,21 +14,21 @@
{{#ifConditional this.totalPages '>' 1}} {{#ifConditional this.totalPages '>' 1}}
<div class="row"> <div class="row">
<div class="column column--3 align-content--left"> <div class="column column--3 align-content--left">
<a class="link--primary" href="/{{this.channelName}}:{{this.longChannelId}}?p=1">First [1]</a> <a class="link--primary" href="/{{this.channelName}}:{{this.longChannelClaimId}}?p=1">First [1]</a>
</div><div class="column column--4 align-content-center"> </div><div class="column column--4 align-content-center">
{{#if this.previousPage}} {{#if this.previousPage}}
<a class="link--primary" href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.previousPage}}">Previous</a> <a class="link--primary" href="/{{this.channelName}}:{{this.longChannelClaimId}}?p={{this.previousPage}}">Previous</a>
{{else}} {{else}}
<a disabled>Previous</a> <a disabled>Previous</a>
{{/if}} {{/if}}
| |
{{#if this.nextPage}} {{#if this.nextPage}}
<a class="link--primary" href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.nextPage}}">Next</a> <a class="link--primary" href="/{{this.channelName}}:{{this.longChannelClaimId}}?p={{this.nextPage}}">Next</a>
{{else}} {{else}}
<a disabled>Next</a> <a disabled>Next</a>
{{/if}} {{/if}}
</div><div class="column column--3 align-content-right"> </div><div class="column column--3 align-content-right">
<a class="link--primary" href="/{{this.channelName}}:{{this.longChannelId}}?p={{this.totalPages}}">Last [{{this.totalPages}}]</a> <a class="link--primary" href="/{{this.channelName}}:{{this.longChannelClaimId}}?p={{this.totalPages}}">Last [{{this.totalPages}}]</a>
</div> </div>
</div> </div>
{{/ifConditional}} {{/ifConditional}}
@ -51,4 +51,4 @@
}); });
</script> </script>

View file

@ -2,11 +2,11 @@
{{#ifConditional this.contentType '===' 'video/mp4'}} {{#ifConditional this.contentType '===' 'video/mp4'}}
<img class="grid-item-image" src="{{this.thumbnail}}"/> <img class="grid-item-image" src="{{this.thumbnail}}"/>
{{else}} {{else}}
<img class="grid-item-image" src="{{this.directUrlLong}}" /> <img class="grid-item-image" src="{{this.claimId}}/{{this.name}}.{{this.fileExt}}" />
{{/ifConditional}} {{/ifConditional}}
<div class="hidden" onclick="window.location='{{this.showUrlLong}}'"> <div class="hidden" onclick="window.location='{{this.claimId}}/{{this.name}}'">
<p class="grid-item-details-text">{{this.name}}</p> <p class="grid-item-details-text">{{this.name}}</p>
</div> </div>
</div> </div>