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 gzip-threshold: 1024
# Secret used for signed cookies. Can be anything, but make it unique and hard to guess # Secret used for signed cookies. Can be anything, but make it unique and hard to guess
cookie-secret: 'change-me' 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 server details
https: https:

View File

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

View File

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

View File

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

View File

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