React router #343
|
@ -1,6 +1,6 @@
|
||||||
const db = require('../models');
|
const db = require('../models');
|
||||||
const logger = require('winston');
|
const logger = require('winston');
|
||||||
const { returnPaginatedChannelViewData } = require('../helpers/channelPagination.js');
|
const { returnPaginatedChannelClaims } = require('../helpers/channelPagination.js');
|
||||||
|
|
||||||
const NO_CHANNEL = 'NO_CHANNEL';
|
const NO_CHANNEL = 'NO_CHANNEL';
|
||||||
const NO_CLAIM = 'NO_CLAIM';
|
const NO_CLAIM = 'NO_CLAIM';
|
||||||
|
@ -53,7 +53,7 @@ module.exports = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
getChannelViewData (channelName, channelClaimId, page) {
|
getChannelData (channelName, channelClaimId, page) {
|
||||||
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)
|
||||||
|
@ -62,14 +62,41 @@ module.exports = {
|
||||||
return [null, null, null];
|
return [null, null, null];
|
||||||
}
|
}
|
||||||
// 2. get the short ID and all claims for that channel
|
// 2. get the short ID and all claims for that channel
|
||||||
return Promise.all([longChannelClaimId, db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName), db.Claim.getAllChannelClaims(longChannelClaimId)]);
|
return Promise.all([longChannelClaimId, db.Certificate.getShortChannelIdFromLongChannelId(longChannelClaimId, channelName)]);
|
||||||
})
|
})
|
||||||
.then(([longChannelClaimId, shortChannelClaimId, channelClaimsArray]) => {
|
.then(([longChannelClaimId, shortChannelClaimId]) => {
|
||||||
|
if (!longChannelClaimId) {
|
||||||
|
return resolve(NO_CHANNEL);
|
||||||
|
}
|
||||||
|
// 3. return all the channel information
|
||||||
|
resolve({
|
||||||
|
channelName,
|
||||||
|
longChannelClaimId,
|
||||||
|
shortChannelClaimId,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
},
|
||||||
|
getChannelClaims (channelName, channelClaimId, page) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
// 1. get the long channel Id (make sure channel exists)
|
||||||
|
db.Certificate.getLongChannelId(channelName, channelClaimId)
|
||||||
|
.then(longChannelClaimId => {
|
||||||
|
if (!longChannelClaimId) {
|
||||||
|
return [null, null, null];
|
||||||
|
}
|
||||||
|
// 2. get the short ID and all claims for that channel
|
||||||
|
return Promise.all([longChannelClaimId, db.Claim.getAllChannelClaims(longChannelClaimId)]);
|
||||||
|
})
|
||||||
|
.then(([longChannelClaimId, channelClaimsArray]) => {
|
||||||
if (!longChannelClaimId) {
|
if (!longChannelClaimId) {
|
||||||
return resolve(NO_CHANNEL);
|
return resolve(NO_CHANNEL);
|
||||||
}
|
}
|
||||||
// 3. format the data for the view, including pagination
|
// 3. format the data for the view, including pagination
|
||||||
let paginatedChannelViewData = returnPaginatedChannelViewData(channelName, longChannelClaimId, shortChannelClaimId, channelClaimsArray, page);
|
let paginatedChannelViewData = returnPaginatedChannelClaims(channelName, longChannelClaimId, channelClaimsArray, page);
|
||||||
// 4. return all the channel information and contents
|
// 4. return all the channel information and contents
|
||||||
resolve(paginatedChannelViewData);
|
resolve(paginatedChannelViewData);
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
const CLAIMS_PER_PAGE = 10;
|
const CLAIMS_PER_PAGE = 12;
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
returnPaginatedChannelViewData (channelName, longChannelClaimId, shortChannelClaimId, claims, page) {
|
returnPaginatedChannelClaims (channelName, longChannelClaimId, claims, page) {
|
||||||
const totalPages = module.exports.determineTotalPages(claims);
|
const totalPages = module.exports.determineTotalPages(claims);
|
||||||
const paginationPage = module.exports.getPageFromQuery(page);
|
const paginationPage = module.exports.getPageFromQuery(page);
|
||||||
const viewData = {
|
const viewData = {
|
||||||
channelName : channelName,
|
channelName : channelName,
|
||||||
longChannelClaimId: longChannelClaimId,
|
longChannelClaimId: longChannelClaimId,
|
||||||
shortChannelClaimId: shortChannelClaimId,
|
|
||||||
claims : module.exports.extractPageFromClaims(claims, paginationPage),
|
claims : module.exports.extractPageFromClaims(claims, paginationPage),
|
||||||
previousPage : module.exports.determinePreviousPage(paginationPage),
|
previousPage : module.exports.determinePreviousPage(paginationPage),
|
||||||
currentPage : paginationPage,
|
currentPage : paginationPage,
|
||||||
|
@ -30,7 +29,7 @@ module.exports = {
|
||||||
// logger.debug('claims is array?', Array.isArray(claims));
|
// logger.debug('claims is array?', Array.isArray(claims));
|
||||||
// logger.debug(`pageNumber ${pageNumber} is number?`, Number.isInteger(pageNumber));
|
// logger.debug(`pageNumber ${pageNumber} is number?`, Number.isInteger(pageNumber));
|
||||||
const claimStartIndex = (pageNumber - 1) * CLAIMS_PER_PAGE;
|
const claimStartIndex = (pageNumber - 1) * CLAIMS_PER_PAGE;
|
||||||
const claimEndIndex = claimStartIndex + 10;
|
const claimEndIndex = claimStartIndex + CLAIMS_PER_PAGE;
|
||||||
const pageOfClaims = claims.slice(claimStartIndex, claimEndIndex);
|
const pageOfClaims = claims.slice(claimStartIndex, claimEndIndex);
|
||||||
return pageOfClaims;
|
return pageOfClaims;
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
oops oops
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Link } from 'react-router-dom';
|
import { Link } from 'react-router-dom'
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
|
|
||||||
const AssetPreview = ({ name, claimId, fileExt, contentType }) => {
|
const AssetPreview = ({ name, claimId, fileExt, contentType }) => {
|
||||||
const directSourceLink = `${claimId}/${name}.${fileExt}`;
|
const directSourceLink = `${claimId}/${name}.${fileExt}`;
|
||||||
|
@ -17,36 +17,36 @@ const AssetPreview = ({ name, claimId, fileExt, contentType }) => {
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
padding: '0px',
|
padding: '0px',
|
||||||
margin : '0px',
|
margin : '0px',
|
||||||
};
|
};
|
||||||
|
return (
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
|
<div style={previewHolderStyle}>
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
|
<Link to={showUrlLink} >
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
|
{(() => {
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
switch (contentType) {
|
switch (contentType) {
|
||||||
case 'image/jpeg':
|
case 'image/jpeg':
|
||||||
case 'image/jpg':
|
case 'image/jpg':
|
||||||
case 'image/png':
|
case 'image/png':
|
||||||
return (
|
return (
|
||||||
<div style={previewHolderStyle}>
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
<Link to={showUrlLink} >
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
<img style={assetStyle} className={'asset-preview--image'} src={directSourceLink} alt={name}/>
|
<img style={assetStyle} className={'asset-preview--image'} src={directSourceLink} alt={name}/>
|
||||||
</Link>
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
</div>
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
);
|
);
|
||||||
case 'image/gif':
|
case 'image/gif':
|
||||||
return (
|
return (
|
||||||
<div style={previewHolderStyle}>
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
<img style={assetStyle} className={'asset-preview--gif'} src={directSourceLink} alt={name}/>
|
<img style={assetStyle} className={'asset-preview--gif'} src={directSourceLink} alt={name}/>
|
||||||
</div>
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
);
|
);
|
||||||
case 'video/mp4':
|
case 'video/mp4':
|
||||||
return (
|
return (
|
||||||
<div style={previewHolderStyle}>
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
<video style={assetStyle}>
|
<video style={assetStyle}>
|
||||||
<source src={directSourceLink} type={contentType}/>
|
<source src={directSourceLink} type={contentType}/>
|
||||||
</video>
|
</video>
|
||||||
</div>
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
);
|
);
|
||||||
default:
|
default:
|
||||||
return (
|
return (
|
||||||
<p>unsupported file type</p>
|
<p>unsupported file type</p>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
})()}
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
|
</Link>
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
|
</div>
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
|
);
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default AssetPreview;
|
export default AssetPreview;
|
||||||
|
|
||||||
Any reason these aren't just css? Any reason these aren't just css?
oops oops
Any reason these aren't just css? Any reason these aren't just css?
oops oops
|
72
react/components/ChannelClaimsDisplay/index.js
Normal file
|
@ -0,0 +1,72 @@
|
||||||
|
import React from 'react';
|
||||||
|
import NavBar from 'containers/NavBar';
|
||||||
|
import AssetPreview from 'components/AssetPreview';
|
||||||
|
import request from 'utils/request';
|
||||||
|
|
||||||
|
class ChannelClaimsDisplay extends React.Component {
|
||||||
|
constructor (props) {
|
||||||
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
error: null,
|
||||||
|
page : 1,
|
||||||
|
};
|
||||||
|
this.getAndStoreChannelClaims = this.getAndStoreChannelClaims.bind(this);
|
||||||
|
}
|
||||||
|
componentDidMount () {
|
||||||
|
const channelName = this.props.channelName;
|
||||||
|
const channelClaimId = this.props.channelClaimId || 'none';
|
||||||
|
const page = this.state.page;
|
||||||
|
this.getAndStoreChannelClaims(channelName, channelClaimId, page);
|
||||||
|
}
|
||||||
|
getAndStoreChannelClaims (channelName, channelClaimId, page) {
|
||||||
|
const url = `/api/channel-claims/${channelName}/${channelClaimId}/${page}`;
|
||||||
|
const that = this;
|
||||||
|
return request(url)
|
||||||
|
.then(({ success, message, data }) => {
|
||||||
|
console.log('api/channel-claims response:', data);
|
||||||
|
if (!success) {
|
||||||
|
return that.setState({error: message});
|
||||||
|
}
|
||||||
|
that.setState({
|
||||||
|
claims : data.claims,
|
||||||
|
currentPage : data.currentPage,
|
||||||
|
nextPage : data.nextPage,
|
||||||
|
previousPage: data.previousPage,
|
||||||
|
totalPages : data.totalPages,
|
||||||
|
totalResults: data.totalResults,
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
that.setState({error: error.message});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
render () {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
{this.state.error ? (
|
||||||
|
<div className="row">
|
||||||
|
<div className="column column--10">
|
||||||
|
<p>{this.state.error}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="row row--tall">
|
||||||
|
<p># of claims in channel: {this.state.totalResults >= 0 ? this.state.totalResults : 'loading...' }</p>
|
||||||
|
{this.state.claims && this.state.claims.map((claim, index) => <AssetPreview
|
||||||
|
name={claim.name}
|
||||||
|
claimId={claim.claimId}
|
||||||
|
contentType={claim.contentType}
|
||||||
|
key={index}
|
||||||
|
/>)}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// required props
|
||||||
|
// channelName
|
||||||
|
// channelClaimId
|
||||||
|
|
||||||
|
export default ChannelClaimsDisplay;
|
|
@ -1,6 +1,6 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import NavBar from 'containers/NavBar';
|
import NavBar from 'containers/NavBar';
|
||||||
import AssetPreview from 'components/AssetPreview';
|
import ChannelClaimsDisplay from 'components/ChannelClaimsDisplay';
|
||||||
import request from 'utils/request';
|
import request from 'utils/request';
|
||||||
|
|
||||||
class ShowChannel extends React.Component {
|
class ShowChannel extends React.Component {
|
||||||
|
@ -8,42 +8,27 @@ class ShowChannel extends React.Component {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
error: null,
|
error: null,
|
||||||
channelName : null,
|
|
||||||
claims : null,
|
|
||||||
currentPage : null,
|
|
||||||
longChannelClaimId : null,
|
|
||||||
nextPage : null,
|
|
||||||
previousPage : null,
|
|
||||||
shortChannelClaimId: null,
|
|
||||||
totalPages : null,
|
|
||||||
totalResults : null,
|
|
||||||
};
|
};
|
||||||
this.updateChannelData = this.updateChannelData.bind(this);
|
this.getAndStoreChannelData = this.getAndStoreChannelData.bind(this);
|
||||||
}
|
}
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
this.updateChannelData(1);
|
|
||||||
}
|
|
||||||
updateChannelData (page) {
|
|
||||||
const channelName = this.props.channelName;
|
const channelName = this.props.channelName;
|
||||||
const channelClaimId = this.props.channelClaimId || 'none';
|
const channelClaimId = this.props.channelClaimId || 'none';
|
||||||
const url = `/api/channel-get-content/${channelName}/${channelClaimId}/${page}`;
|
this.getAndStoreChannelData(channelName, channelClaimId);
|
||||||
|
}
|
||||||
|
getAndStoreChannelData (channelName, channelClaimId) {
|
||||||
|
const url = `/api/channel-data/${channelName}/${channelClaimId}`;
|
||||||
const that = this;
|
const that = this;
|
||||||
return request(url)
|
return request(url)
|
||||||
.then(({ success, message, data }) => {
|
.then(({ success, message, data }) => {
|
||||||
console.log('get channel data response:', data);
|
console.log('api/channel-data response:', data);
|
||||||
if (!success) {
|
if (!success) {
|
||||||
return that.setState({error: message});
|
return that.setState({error: message});
|
||||||
}
|
}
|
||||||
that.setState({
|
that.setState({
|
||||||
channelName : data.channelName,
|
channelName : data.channelName,
|
||||||
claims : data.claims,
|
|
||||||
currentPage : data.currentPage,
|
|
||||||
longChannelClaimId : data.longChannelClaimId,
|
longChannelClaimId : data.longChannelClaimId,
|
||||||
nextPage : data.nextPage,
|
|
||||||
previousPage : data.previousPage,
|
|
||||||
shortChannelClaimId: data.shortChannelClaimId,
|
shortChannelClaimId: data.shortChannelClaimId,
|
||||||
totalPages : data.totalPages,
|
|
||||||
totalResults : data.totalResults,
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
|
@ -66,18 +51,14 @@ class ShowChannel extends React.Component {
|
||||||
<h2>channel name: {this.props.channelName}</h2>
|
<h2>channel name: {this.props.channelName}</h2>
|
||||||
<p>full channel id: {this.state.longChannelClaimId ? this.state.longChannelClaimId : 'loading...'}</p>
|
<p>full channel id: {this.state.longChannelClaimId ? this.state.longChannelClaimId : 'loading...'}</p>
|
||||||
<p>short channel id: {this.state.shortChannelClaimId ? this.state.shortChannelClaimId : 'loading...'}</p>
|
<p>short channel id: {this.state.shortChannelClaimId ? this.state.shortChannelClaimId : 'loading...'}</p>
|
||||||
<p># of claims in channel: {this.state.totalResults >= 0 ? this.state.totalResults : 'loading...' }</p>
|
|
||||||
</div>
|
</div>
|
||||||
<div className="column column--10">
|
<div className="column column--10">
|
||||||
<div>
|
{ (this.state.channelName && this.state.longChannelClaimId) &&
|
||||||
{/* claims here */}
|
<ChannelClaimsDisplay
|
||||||
{this.state.claims && this.state.claims.map((claim, index) => <AssetPreview
|
channelName={this.state.channelName}
|
||||||
name={claim.name}
|
channelClaimId={this.state.longChannelClaimId}
|
||||||
claimId={claim.claimId}
|
/>
|
||||||
contentType={claim.contentType}
|
}
|
||||||
key={index}
|
|
||||||
/>)}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
|
@ -9,7 +9,7 @@ const { createPublishParams, parsePublishApiRequestBody, parsePublishApiRequestF
|
||||||
const errorHandlers = require('../helpers/errorHandlers.js');
|
const errorHandlers = require('../helpers/errorHandlers.js');
|
||||||
const { sendGoogleAnalyticsTiming } = require('../helpers/statsHelpers.js');
|
const { sendGoogleAnalyticsTiming } = require('../helpers/statsHelpers.js');
|
||||||
const { authenticateIfNoUserToken } = require('../auth/authentication.js');
|
const { authenticateIfNoUserToken } = require('../auth/authentication.js');
|
||||||
const { getChannelViewData, getClaimId } = require('../controllers/serveController.js');
|
const { getChannelData, getChannelClaims, getClaimId } = require('../controllers/serveController.js');
|
||||||
|
|
||||||
const NO_CHANNEL = 'NO_CHANNEL';
|
const NO_CHANNEL = 'NO_CHANNEL';
|
||||||
const NO_CLAIM = 'NO_CLAIM';
|
const NO_CLAIM = 'NO_CLAIM';
|
||||||
|
@ -189,12 +189,28 @@ module.exports = (app) => {
|
||||||
errorHandlers.handleApiError(originalUrl, ip, error, res);
|
errorHandlers.handleApiError(originalUrl, ip, error, res);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
app.get('/api/channel-get-content/:name/:longId/:page', ({ ip, originalUrl, body, params }, res) => {
|
app.get('/api/channel-data/:channelName/:channelClaimId', ({ ip, originalUrl, body, params }, res) => {
|
||||||
const channelName = params.name;
|
const channelName = params.channelName;
|
||||||
let channelClaimId = params.longId;
|
let channelClaimId = params.channelClaimId;
|
||||||
|
if (channelClaimId === 'none') channelClaimId = null;
|
||||||
|
getChannelData(channelName, channelClaimId, 0) // getChannelViewData(channelName, channelId, 0)
|
||||||
|
.then(data => {
|
||||||
|
if (data === NO_CHANNEL) {
|
||||||
|
return res.status(200).json({success: false, message: 'No matching channel was found'});
|
||||||
|
}
|
||||||
|
res.status(200).json({success: true, data});
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
logger.error('api error getting channel contents', error);
|
||||||
|
errorHandlers.handleApiError(originalUrl, ip, error, res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.get('/api/channel-claims/:channelName/:channelClaimId/:page', ({ ip, originalUrl, body, params }, res) => {
|
||||||
|
const channelName = params.channelName;
|
||||||
|
let channelClaimId = params.channelClaimId;
|
||||||
if (channelClaimId === 'none') channelClaimId = null;
|
if (channelClaimId === 'none') channelClaimId = null;
|
||||||
const page = params.page;
|
const page = params.page;
|
||||||
getChannelViewData(channelName, channelClaimId, page)
|
getChannelClaims(channelName, channelClaimId, page)// getChannelViewData(channelName, channelClaimId, page)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
if (data === NO_CHANNEL) {
|
if (data === NO_CHANNEL) {
|
||||||
return res.status(200).json({success: false, message: 'No matching channel was found'});
|
return res.status(200).json({success: false, message: 'No matching channel was found'});
|
||||||
|
|
Any reason these aren't just css?