lintageddon 3

This commit is contained in:
Josh Burman 2020-02-03 16:41:13 -05:00
parent e9d7650ffe
commit 6ec98af769
15 changed files with 30 additions and 31 deletions

View File

@ -34,7 +34,7 @@ class ChannelManager {
channelExists(channel_id: string) { channelExists(channel_id: string) {
for (let channel of this.channels) { for (let channel of this.channels) {
if (channel.id == channel_id) { if (channel.id === channel_id) {
return channel; return channel;
} }
} }
@ -59,7 +59,7 @@ class ChannelManager {
try { try {
logger.accessLog.info(`attempting to create channel of type ${data.channel_type}, channel id: ${data.channel}...`); logger.accessLog.info(`attempting to create channel of type ${data.channel_type}, channel id: ${data.channel}...`);
if (data.channel_type == 'public') { if (data.channel_type === 'public') {
return new PublicChannel(data.channel); return new PublicChannel(data.channel);
} else if (data.channel_type == 'private') { } else if (data.channel_type == 'private') {
return new PrivateChannel(data.channel); return new PrivateChannel(data.channel);
@ -82,7 +82,7 @@ class ChannelManager {
return true; return true;
} else { } else {
logger.errorLog.info(`client not removed from channel, or doesn't exist in channel - channel: ${channel_id}, client: ${client_id}`); logger.errorLog.info(`client not removed from channel, or doesn't exist in channel - channel: ${channel_id}, client: ${client_id}`);
return false return false;
} }
} }
} }
@ -95,16 +95,16 @@ class ChannelManager {
this.removeClientFromChannel(client.id, client.channel.id); this.removeClientFromChannel(client.id, client.channel.id);
} }
let channel = this.createChannel(changeRequest); const channel = this.createChannel(changeRequest);
this.addClientToChannel(client, channel.id); this.addClientToChannel(client, channel.id);
let message = {message_type: 'requestExamStatus'}; const message = {message_type: 'requestExamStatus'};
channel.broadcastMessage(client, message); channel.broadcastMessage(client, message);
this.purgeEmptyChannels(); this.purgeEmptyChannels();
} }
purgeEmptyChannels() { purgeEmptyChannels() {
for (const channel of this.channels) { for (const channel of this.channels) {
if (channel.clients.length == 0 && channel.id != 'default') { if (channel.clients.length === 0 && channel.id !== 'default') {
const index = this.channels.indexOf(channel); const index = this.channels.indexOf(channel);
this.channels.splice(index, 1); this.channels.splice(index, 1);
logger.accessLog.info(`channel removed: ${channel.id}`); logger.accessLog.info(`channel removed: ${channel.id}`);

View File

@ -54,7 +54,7 @@ class ChannelBase {
removeClient(id: number) { removeClient(id: number) {
for (let client of this.clients) { for (let client of this.clients) {
if (client.id === id) { if (client.id === id) {
let index = this.clients.indexOf(client) const index = this.clients.indexOf(client)
this.clients.splice(index, 1); this.clients.splice(index, 1);
return true; return true;
} }

View File

@ -7,7 +7,7 @@ class PublicChannel extends ChannelBase {
messageTransactionPossible(from: PublicClient, to: PublicClient) { messageTransactionPossible(from: PublicClient, to: PublicClient) {
return ( return (
to !== from to !== from
) );
} }
}; };

View File

@ -10,7 +10,7 @@ class ClientManager {
clients: any[] = []; clients: any[] = [];
constructor() { constructor() {
//...maybe one day // ...maybe one day
} }
addClient(data: any, channelManager: ChannelManager, ws: WebSocket) { addClient(data: any, channelManager: ChannelManager, ws: WebSocket) {
@ -39,7 +39,7 @@ class ClientManager {
} }
clientExists(id: number) { clientExists(id: number) {
for (let client of this.clients) { for (const client of this.clients) {
if (client.id === id) { if (client.id === id) {
return client; return client;
} }
@ -84,6 +84,6 @@ class ClientManager {
return new PublicClient(data, ws, channelManager, this); return new PublicClient(data, ws, channelManager, this);
} }
} }
}; }
export default ClientManager; export default ClientManager;

View File

@ -95,6 +95,6 @@ class ClientBase {
this.ws.close(); this.ws.close();
this.ws = ws; this.ws = ws;
} }
}; }
export default ClientBase; export default ClientBase;

View File

@ -9,7 +9,7 @@ class CustomClient extends ClientBase {
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) { constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
super(data, ws, channelManager, clientManager); super(data, ws, channelManager, clientManager);
this.roles = data.user_roles; this.roles = data.user_roles;
logger.accessLog.info('Custom Client Created', {data: data}); logger.accessLog.info('Custom Client Created', {data});
} }
} }

View File

@ -9,8 +9,8 @@ class PrivateClient extends ClientBase {
constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) { constructor(data: any, ws: WebSocket, channelManager: ChannelManager, clientManager: ClientManager) {
super(data, ws, channelManager, clientManager); super(data, ws, channelManager, clientManager);
this.roles = data.user_roles; this.roles = data.user_roles;
logger.accessLog.info('Private Client Created', {data: data}); logger.accessLog.info('Private Client Created', {data});
} }
}; }
export default PrivateClient; export default PrivateClient;

View File

@ -1,5 +1,5 @@
import ClientBase from '../clientBase'; import ClientBase from '../clientBase';
class PublicClient extends ClientBase {}; class PublicClient extends ClientBase {}
export default PublicClient; export default PublicClient;

View File

@ -1,7 +1,7 @@
var app = require('../config/app') const app = require('../config/app');
module.exports = { module.exports = {
home : (req: any, res: any) => { home: (req: any, res: any) => {
res.send(`Welcome to Braid v${app.version}`) res.send(`Welcome to Braid v${app.version}`)
} }
}; };

View File

@ -1,12 +1,12 @@
import * as jwt from 'jsonwebtoken'; import * as jwt from 'jsonwebtoken';
const app = require('../config/app'); const app = require('../config/app');
module.exports = { module.exports = {
confirmToken : (req: any, res: any) => { confirmToken : (req: any, res: any) => {
let token = req.body.token const token = req.body.token
res.json({ res.json({
response: JSON.stringify(jwt.verify(token, app.secret, app.signOptions)) response: JSON.stringify(jwt.verify(token, app.secret, app.signOptions))
}); });
} }
} };

View File

@ -1,5 +1,5 @@
module.exports = { module.exports = {
clientExists: function(id: number) { clientExists(id: number) {
for (const client of this.clients) { for (const client of this.clients) {
if (client.id === id) { if (client.id === id) {
return client; return client;

View File

@ -14,7 +14,7 @@ function loggerTransports(logName: string, logLevel: string) {
timestamp: tsFormat, timestamp: tsFormat,
level: logLevel level: logLevel
}) })
] ];
} }
const errorLog = createLogger({ const errorLog = createLogger({
@ -27,7 +27,6 @@ const accessLog = createLogger({
transports: loggerTransports('access', 'info') transports: loggerTransports('access', 'info')
}); });
module.exports = { module.exports = {
errorLog: errorLog, errorLog: errorLog,
accessLog: accessLog accessLog: accessLog

View File

@ -14,11 +14,11 @@ const corsOptions = {
const router = express.Router(); const router = express.Router();
//application // application
const appController = require('./controllers/appController'); const appController = require('./controllers/appController');
router.route(['/', '/home']).get(appController.home) router.route(['/', '/home']).get(appController.home);
//auth // auth
const authController = require('./controllers/authController'); const authController = require('./controllers/authController');
router.route('/auth/user').post(cors(), authController.confirmToken); router.route('/auth/user').post(cors(), authController.confirmToken);

View File

@ -74,7 +74,7 @@ function startServer() {
startServer(); startServer();
module.exports = { module.exports = {
clientManager: clientManager, clientManager,
channelManager: channelManager, channelManager,
connectionManager: connectionManager connectionManager
}; };

View File

@ -1,4 +1,4 @@
import * as Joi from 'joi' import * as Joi from 'joi';
const app = require('../config/app'); const app = require('../config/app');