From aedd0df228f0c09c7999961913045f0d31ce4e44 Mon Sep 17 00:00:00 2001 From: calzoneman Date: Sat, 21 May 2016 16:59:28 -0700 Subject: [PATCH] Limit the number of channels displayed on the index page --- config.template.yaml | 3 +++ src/config.js | 5 ++++- src/configuration/webconfig.js | 6 ++++++ src/web/routes/index.js | 4 +++- src/web/webserver.js | 2 +- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/config.template.yaml b/config.template.yaml index 5930aec4..269428ad 100644 --- a/config.template.yaml +++ b/config.template.yaml @@ -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: diff --git a/src/config.js b/src/config.js index e437efb8..6b24f2ae 100644 --- a/src/config.js +++ b/src/config.js @@ -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, diff --git a/src/configuration/webconfig.js b/src/configuration/webconfig.js index aee7322a..ae1f888d 100644 --- a/src/configuration/webconfig.js +++ b/src/configuration/webconfig.js @@ -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); }; diff --git a/src/web/routes/index.js b/src/web/routes/index.js index 86aaf9b9..e416376e 100644 --- a/src/web/routes/index.js +++ b/src/web/routes/index.js @@ -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 }); diff --git a/src/web/webserver.js b/src/web/webserver.js index 379b4029..30de9ea0 100644 --- a/src/web/webserver.js +++ b/src/web/webserver.js @@ -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);