Development #287
6 changed files with 28 additions and 39 deletions
|
@ -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 => {
|
||||
|
|
|
@ -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(', ')}.`);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<div class="row row--padded">
|
||||
<div class="row">
|
||||
{{#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 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">
|
||||
{{#each this.claims}}
|
||||
{{> gridItem}}
|
||||
|
@ -14,21 +14,21 @@
|
|||
{{#ifConditional this.totalPages '>' 1}}
|
||||
<div class="row">
|
||||
<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">
|
||||
{{#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}}
|
||||
<a disabled>Previous</a>
|
||||
{{/if}}
|
||||
|
|
||||
{{#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}}
|
||||
<a disabled>Next</a>
|
||||
{{/if}}
|
||||
</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>
|
||||
{{/ifConditional}}
|
||||
|
@ -51,4 +51,4 @@
|
|||
});
|
||||
|
||||
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
@ -2,11 +2,11 @@
|
|||
{{#ifConditional this.contentType '===' 'video/mp4'}}
|
||||
<img class="grid-item-image" src="{{this.thumbnail}}"/>
|
||||
{{else}}
|
||||
<img class="grid-item-image" src="{{this.directUrlLong}}" />
|
||||
<img class="grid-item-image" src="{{this.claimId}}/{{this.name}}.{{this.fileExt}}" />
|
||||
{{/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>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue