Limit the number of channels displayed on the index page

This commit is contained in:
calzoneman 2016-05-21 16:59:28 -07:00
parent beb99c5632
commit aedd0df228
5 changed files with 17 additions and 3 deletions

View File

@ -66,6 +66,9 @@ http:
gzip-threshold: 1024
# Secret used for signed cookies. Can be anything, but make it unique and hard to guess
cookie-secret: 'change-me'
index:
# Maximum number of channels to display on the index page public channel list
max-entries: 50
# HTTPS server details
https:

View File

@ -34,7 +34,10 @@ var defaults = {
"max-age": "7d",
gzip: true,
"gzip-threshold": 1024,
"cookie-secret": "change-me"
"cookie-secret": "change-me",
index: {
"max-entries": 50
}
},
https: {
enabled: false,

View File

@ -41,6 +41,10 @@ export default class WebConfiguration {
getCacheTTL() {
return this.config.cacheTTL;
}
getMaxIndexEntries() {
return this.config.maxIndexEntries;
}
}
WebConfiguration.fromOldConfig = function (oldConfig) {
@ -70,5 +74,7 @@ WebConfiguration.fromOldConfig = function (oldConfig) {
config.cacheTTL = oldConfig.get('http.max-age');
config.maxIndexEntries = oldConfig.get('http.index.max-entries');
return new WebConfiguration(config);
};

View File

@ -1,6 +1,6 @@
import { sendJade } from '../jade';
export default function initialize(app, channelIndex) {
export default function initialize(app, channelIndex, maxEntries) {
app.get('/', (req, res) => {
channelIndex.listPublicChannels().then((channels) => {
channels.sort((a, b) => {
@ -11,6 +11,8 @@ export default function initialize(app, channelIndex) {
return b.usercount - a.usercount;
});
channels = channels.slice(0, maxEntries);
sendJade(res, 'index', {
channels: channels
});

View File

@ -168,7 +168,7 @@ module.exports = {
}
require('./routes/channel')(app, ioConfig);
require('./routes/index')(app, channelIndex);
require('./routes/index')(app, channelIndex, webConfig.getMaxIndexEntries());
app.get('/sioconfig(.json)?', handleLegacySocketConfig);
require('./routes/socketconfig')(app, clusterClient);
app.get('/useragreement', handleUserAgreement);