Web refactoring
This commit is contained in:
parent
566e932e7e
commit
50ca141f1d
10 changed files with 106 additions and 75 deletions
25
src/web/routes/channel.js
Normal file
25
src/web/routes/channel.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
import CyTubeUtil from '../../utilities';
|
||||
import { sanitizeText } from '../../xss';
|
||||
import { sendJade } from '../jade';
|
||||
import * as HTTPStatus from '../httpstatus';
|
||||
import { HTTPError } from '../../errors';
|
||||
|
||||
export default function initialize(app, ioConfig) {
|
||||
app.get('/r/:channel', (req, res) => {
|
||||
if (!req.params.channel || !CyTubeUtil.isValidChannelName(req.params.channel)) {
|
||||
throw new HTTPError(`"${sanitizeText(req.params.channel)} is not a valid ` +
|
||||
'channel name.', { status: HTTPStatus.BAD_REQUEST });
|
||||
}
|
||||
|
||||
const endpoints = ioConfig.getSocketEndpoints();
|
||||
if (endpoints.length === 0) {
|
||||
throw new HTTPError('No socket.io endpoints configured');
|
||||
}
|
||||
const socketBaseURL = endpoints[0].url;
|
||||
|
||||
sendJade(res, 'channel', {
|
||||
channelName: req.params.channel,
|
||||
sioSource: `${socketBaseURL}/socket.io/socket.io.js`
|
||||
});
|
||||
});
|
||||
}
|
||||
19
src/web/routes/index.js
Normal file
19
src/web/routes/index.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { sendJade } from '../jade';
|
||||
|
||||
export default function initialize(app, channelIndex) {
|
||||
app.get('/', (req, res) => {
|
||||
channelIndex.listPublicChannels().then((channels) => {
|
||||
channels.sort((a, b) => {
|
||||
if (a.usercount === b.usercount) {
|
||||
return a.uniqueName > b.uniqueName ? -1 : 1;
|
||||
}
|
||||
|
||||
return b.usercount - a.usercount;
|
||||
});
|
||||
|
||||
sendJade(res, 'index', {
|
||||
channels: channels
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
@ -1,16 +1,12 @@
|
|||
import IOConfiguration from '../../configuration/ioconfig';
|
||||
import NullClusterClient from '../../io/cluster/nullclusterclient';
|
||||
import Config from '../../config';
|
||||
import CyTubeUtil from '../../utilities';
|
||||
import Logger from '../../logger';
|
||||
import * as HTTPStatus from '../httpstatus';
|
||||
|
||||
export default function initialize(app) {
|
||||
const ioConfig = IOConfiguration.fromOldConfig(Config);
|
||||
const clusterClient = new NullClusterClient(ioConfig);
|
||||
|
||||
export default function initialize(app, clusterClient) {
|
||||
app.get('/socketconfig/:channel.json', (req, res) => {
|
||||
if (!req.params.channel || !CyTubeUtil.isValidChannelName(req.params.channel)) {
|
||||
return res.status(404).json({
|
||||
return res.status(HTTPStatus.NOT_FOUND).json({
|
||||
error: `Channel "${req.params.channel}" does not exist.`
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue