Resolve channels #150

Merged
bones7242 merged 23 commits from resolve-channels into master 2017-08-25 18:35:40 +02:00
5 changed files with 72 additions and 15 deletions
Showing only changes of commit a23aa0bb82 - Show all commits

View file

@ -156,4 +156,18 @@ module.exports = {
});
});
},
getRecentClaims (startDate) {
logger.debug('retrieving most recent claims');
return new Promise((resolve, reject) => {
// get the raw requests data
db.sequelize.query(`SELECT * FROM File WHERE nsfw != 1 AND trendingEligible = 1 ORDER BY createdAt DESC LIMIT 25;`, { type: db.sequelize.QueryTypes.SELECT })
kauffj commented 2017-08-25 19:27:57 +02:00 (Migrated from github.com)
Review

Try to avoid SQL in your controllers and keep it located in the modal layer. This helps facilitates future modal refactoring/redesign and keeps controllers simpler (controllers are typically then thinnest of the 3 MVC layers).

Try to avoid SQL in your controllers and keep it located in the modal layer. This helps facilitates future modal refactoring/redesign and keeps controllers simpler (controllers are typically then thinnest of the 3 MVC layers).
bones7242 commented 2017-09-07 21:37:15 +02:00 (Migrated from github.com)
Review

moved to model 4d94acee77

moved to model https://github.com/lbryio/spee.ch/commit/4d94acee77cd90341f23ab5d39d2ba90bc7edf2c
.then(results => {
resolve(results);
})
.catch(error => {
logger.error('sequelize error', error);
reject(error);
});
});
},
};

View file

@ -1,6 +1,6 @@
const errorHandlers = require('../helpers/errorHandlers.js');
const { getAllFreeClaims } = require('../helpers/serveHelpers.js');
const { postToStats, getStatsSummary, getTrendingClaims } = require('../controllers/statsController.js');
const { postToStats, getStatsSummary, getTrendingClaims, getRecentClaims } = require('../controllers/statsController.js');
module.exports = (app) => {
// route to show 'about' page for spee.ch
@ -9,7 +9,7 @@ module.exports = (app) => {
res.status(200).render('about');
});
// route to display a list of the trending images
app.get('/trending', ({ params, headers }, res) => {
app.get('/popular', ({ params, headers }, res) => {
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1);
getTrendingClaims(startDate)
@ -21,6 +21,19 @@ module.exports = (app) => {
errorHandlers.handleRequestError(error, res);
kauffj commented 2017-08-25 19:34:59 +02:00 (Migrated from github.com)
Review

The old URL ought to be 301 redirect to the new one.

The old URL ought to be 301 redirect to the new one.
bones7242 commented 2017-09-07 21:41:26 +02:00 (Migrated from github.com)
Review

added redirect 7a81d53c35

added redirect https://github.com/lbryio/spee.ch/commit/7a81d53c3570d07e8666aee2fbfd7209e7646827
});
});
// route to display a list of the trending images
app.get('/new', ({ params, headers }, res) => {
const startDate = new Date();
startDate.setDate(startDate.getDate() - 1);
getRecentClaims(startDate)
.then(result => {
// logger.debug(result);
res.status(200).render('new', { newClaims: result });
})
.catch(error => {
errorHandlers.handleRequestError(error, res);
});
});
// route to show statistics for spee.ch
app.get('/stats', ({ ip, originalUrl }, res) => {
// get and render the content

26
views/new.handlebars Normal file
View file

@ -0,0 +1,26 @@
<div class="wrapper">
{{> topBar}}
<div>
<h2>New on Spee.ch</h2>
<p><i>The 25 most recent publishes on spee.ch</i></p>
{{#each newClaims}}
<div class="all-claims-item">
<a href="/{{this.claimId}}/{{this.name}}">
{{#ifConditional this.fileType '===' 'video/mp4'}}
<img class="all-claims-asset" src="/assets/img/content-freedom-large.png"/>
{{else}}
<img class="all-claims-asset" src="/{{this.claimId}}/{{this.name}}.ext" />
{{/ifConditional}}
</a>
<div class="all-claims-details">
<ul style="list-style-type:none">
<li><bold>{{this.name}}</bold></li>
<li><i>Claim Id: {{this.claimId}}</i></li>
<li><a href="/{{this.claimId}}/{{this.name}}">Link</a></li>
</ul>
</div>
</div>
{{/each}}
</div>
{{> footer}}
</div>

View file

@ -1,7 +1,8 @@
<div class="top-bar">
<a href="https://en.wikipedia.org/wiki/Freedom_of_information" target="_blank"><img id="logo" src="/assets/img/content-freedom-64px.png"/></a>
<h1 id="title"><a href="/">Spee.ch</a></h1><span class="top-bar-left">(beta)</span>
<a href="/trending" class="top-bar-right">trending</a>
<a href="/new" class="top-bar-right">new</a>
<a href="/popular" class="top-bar-right">popular</a>
<a href="https://github.com/lbryio/spee.ch" target="_blank" class="top-bar-right">source</a>
<a href="/about" class="top-bar-right">help</a>
<div class="top-bar-tagline">Open-source, decentralized image and video hosting.</div>

View file

@ -2,22 +2,25 @@
<div class="full">
<h2>Trending</h2>
<p><i>The 25 most popular assets on spee.ch</i></p>
<div class="grid" data-masonry='{ "itemSelector": ".grid-item" }'>
{{#each trendingAssets}}
{{#unless this.nsfw}}
<div class="all-claims-item">
<a href="/{{this.claimId}}/{{this.name}}">
{{#ifConditional this.fileType '===' 'video/mp4'}}
<video class="grid-item trending-video" controls onloadeddata="resetTrendingLayout()">
<source src="/media/{{this.fileName}}" >
{{!--fallback--}}
Your browser does not support the <code>video</code> element.
</video>
{{else}}
<img class="grid-item trending-image" src="/media/{{this.fileName}}" onload="resetTrendingLayout()"/>
{{/ifConditional}}
{{#ifConditional this.fileType '===' 'video/mp4'}}
<img class="all-claims-asset" src="/assets/img/content-freedom-large.png"/>
{{else}}
<img class="all-claims-asset" src="/{{this.claimId}}/{{this.name}}.ext" />
{{/ifConditional}}
</a>
{{/unless}}
<div class="all-claims-details">
<ul style="list-style-type:none">
<li><bold>{{this.name}}</bold></li>
<li><i>Claim Id: {{this.claimId}}</i></li>
<li><strong>{{this.title}}</strong></li>
</ul>
</div>
</div>
{{/each}}
</div>
</div>