Another stupid lint rule
This commit is contained in:
parent
f4951ac18b
commit
1dcf88c996
1 changed files with 27 additions and 27 deletions
|
@ -1,9 +1,9 @@
|
||||||
import express from 'express';
|
import express from 'express';
|
||||||
import {body, query, validationResult} from 'express-validator';
|
import { body, query, validationResult } from 'express-validator';
|
||||||
import rateLimit from 'express-rate-limit';
|
import rateLimit from 'express-rate-limit';
|
||||||
import cors from 'cors';
|
import cors from 'cors';
|
||||||
import bodyParser from 'body-parser';
|
import bodyParser from 'body-parser';
|
||||||
import {v4 as uuidv4} from 'uuid';
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
import dotenv from 'dotenv';
|
import dotenv from 'dotenv';
|
||||||
import helmet from 'helmet';
|
import helmet from 'helmet';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
@ -83,18 +83,18 @@ app.get('/joinPartyLine', [
|
||||||
], (req: any, res: any) => {
|
], (req: any, res: any) => {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return res.status(400).json({errors: errors.array()});
|
return res.status(400).json({ errors: errors.array() });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const currentPartyLine = req.query.partyLine;
|
const currentPartyLine = req.query.partyLine;
|
||||||
const partyLine = partyLines[currentPartyLine];
|
const partyLine = partyLines[currentPartyLine];
|
||||||
if (!partyLine) {
|
if (!partyLine) {
|
||||||
return res.status(404).send({status: 'Party line not found'});
|
return res.status(404).send({ status: 'Party line not found' });
|
||||||
}
|
}
|
||||||
res.status(200).send({status: 'Connection to party line authorized'});
|
res.status(200).send({ status: 'Connection to party line authorized' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('ERROR: Failed to join party line', error);
|
console.error('ERROR: Failed to join party line', error);
|
||||||
res.status(500).send({status: 'Internal server error'});
|
res.status(500).send({ status: 'Internal server error' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -104,13 +104,13 @@ app.get('/connectPartyLine', [
|
||||||
], (req: any, res: any) => {
|
], (req: any, res: any) => {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return res.status(400).json({errors: errors.array()});
|
return res.status(400).json({ errors: errors.array() });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const connectedPartyLine = req.query.partyLine;
|
const connectedPartyLine = req.query.partyLine;
|
||||||
const partyLine = partyLines[connectedPartyLine];
|
const partyLine = partyLines[connectedPartyLine];
|
||||||
if (!partyLine) {
|
if (!partyLine) {
|
||||||
return res.status(404).send({status: 'Party line not found'});
|
return res.status(404).send({ status: 'Party line not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set headers for Server-Sent Events (SSE)
|
// Set headers for Server-Sent Events (SSE)
|
||||||
|
@ -119,7 +119,7 @@ app.get('/connectPartyLine', [
|
||||||
res.setHeader('Connection', 'keep-alive');
|
res.setHeader('Connection', 'keep-alive');
|
||||||
|
|
||||||
const clientId = `${uuidv4()}`;
|
const clientId = `${uuidv4()}`;
|
||||||
const client = {clientId, response: res};
|
const client = { clientId, response: res };
|
||||||
|
|
||||||
// Add client to the party line
|
// Add client to the party line
|
||||||
partyLine.clients.push(client);
|
partyLine.clients.push(client);
|
||||||
|
@ -162,7 +162,7 @@ app.get('/connectPartyLine', [
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('ERROR: Failed to connect to party line', error);
|
console.error('ERROR: Failed to connect to party line', error);
|
||||||
res.status(500).send({status: 'Internal server error'});
|
res.status(500).send({ status: 'Internal server error' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -187,15 +187,15 @@ app.post('/createPartyLine', [
|
||||||
], (req: any, res: any) => {
|
], (req: any, res: any) => {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return res.status(400).json({errors: errors.array()});
|
return res.status(400).json({ errors: errors.array() });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const {partyLine: currentPartyLine} = req.body;
|
const { partyLine: currentPartyLine } = req.body;
|
||||||
if (Object.keys(partyLines).length >= MAX_PARTY_LINES) {
|
if (Object.keys(partyLines).length >= MAX_PARTY_LINES) {
|
||||||
return res.status(400).send({status: 'Maximum number of party lines reached'});
|
return res.status(400).send({ status: 'Maximum number of party lines reached' });
|
||||||
}
|
}
|
||||||
if (partyLines[currentPartyLine]) {
|
if (partyLines[currentPartyLine]) {
|
||||||
return res.status(400).send({status: 'Party line already exists'});
|
return res.status(400).send({ status: 'Party line already exists' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new party line
|
// Create a new party line
|
||||||
|
@ -206,10 +206,10 @@ app.post('/createPartyLine', [
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log(`CREATE: Created party line: ${currentPartyLine}`);
|
console.log(`CREATE: Created party line: ${currentPartyLine}`);
|
||||||
res.status(200).send({status: 'Party line created', currentPartyLine});
|
res.status(200).send({ status: 'Party line created', currentPartyLine });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('ERROR: Failed to create party line', error);
|
console.error('ERROR: Failed to create party line', error);
|
||||||
res.status(500).send({status: 'Internal server error'});
|
res.status(500).send({ status: 'Internal server error' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -220,13 +220,13 @@ app.post('/rumor', [
|
||||||
], (req: any, res: any) => {
|
], (req: any, res: any) => {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return res.status(400).json({errors: errors.array()});
|
return res.status(400).json({ errors: errors.array() });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const {partyLine: connectedPartyLine, rumor} = req.body;
|
const { partyLine: connectedPartyLine, rumor } = req.body;
|
||||||
const partyLine = partyLines[connectedPartyLine];
|
const partyLine = partyLines[connectedPartyLine];
|
||||||
if (!partyLine) {
|
if (!partyLine) {
|
||||||
return res.status(404).send({status: 'Party line not found'});
|
return res.status(404).send({ status: 'Party line not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(`RECEIVE: Received rumor for party line ${connectedPartyLine}: ${rumor}`);
|
console.log(`RECEIVE: Received rumor for party line ${connectedPartyLine}: ${rumor}`);
|
||||||
|
@ -236,17 +236,17 @@ app.post('/rumor', [
|
||||||
partyLine.clients.forEach((client: any) => {
|
partyLine.clients.forEach((client: any) => {
|
||||||
client.response.write(`data: ${rumor}\n\n`);
|
client.response.write(`data: ${rumor}\n\n`);
|
||||||
});
|
});
|
||||||
res.status(200).send({status: 'Rumor broadcast'});
|
res.status(200).send({ status: 'Rumor broadcast' });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('ERROR: Failed to send event', error);
|
console.error('ERROR: Failed to send event', error);
|
||||||
res.status(500).send({status: 'Internal server error'});
|
res.status(500).send({ status: 'Internal server error' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Route to get all party lines
|
// Route to get all party lines
|
||||||
app.get('/partyLines', (_req: any, res: any) => {
|
app.get('/partyLines', (_req: any, res: any) => {
|
||||||
const allPartyLines = Object.keys(partyLines);
|
const allPartyLines = Object.keys(partyLines);
|
||||||
res.status(200).send({allPartyLines});
|
res.status(200).send({ allPartyLines });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Route to delete a party line
|
// Route to delete a party line
|
||||||
|
@ -255,13 +255,13 @@ app.delete('/deletePartyLine', [
|
||||||
], (req: any, res: any) => {
|
], (req: any, res: any) => {
|
||||||
const errors = validationResult(req);
|
const errors = validationResult(req);
|
||||||
if (!errors.isEmpty()) {
|
if (!errors.isEmpty()) {
|
||||||
return res.status(400).json({errors: errors.array()});
|
return res.status(400).json({ errors: errors.array() });
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const {partyLine: currentPartyLine} = req.body;
|
const { partyLine: currentPartyLine } = req.body;
|
||||||
const partyLine = partyLines[currentPartyLine];
|
const partyLine = partyLines[currentPartyLine];
|
||||||
if (!partyLine) {
|
if (!partyLine) {
|
||||||
return res.status(404).send({status: 'Party line not found'});
|
return res.status(404).send({ status: 'Party line not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
// Broadcast deletion message to all clients
|
// Broadcast deletion message to all clients
|
||||||
|
@ -276,10 +276,10 @@ app.delete('/deletePartyLine', [
|
||||||
// Delete the party line
|
// Delete the party line
|
||||||
delete partyLines[currentPartyLine];
|
delete partyLines[currentPartyLine];
|
||||||
console.log(`DELETE: Deleted party line: ${currentPartyLine}`);
|
console.log(`DELETE: Deleted party line: ${currentPartyLine}`);
|
||||||
res.status(200).send({status: 'Party line deleted', currentPartyLine});
|
res.status(200).send({ status: 'Party line deleted', currentPartyLine });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('ERROR: Failed to delete party line', error);
|
console.error('ERROR: Failed to delete party line', error);
|
||||||
res.status(500).send({status: 'Internal server error'});
|
res.status(500).send({ status: 'Internal server error' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue