diff --git a/src/pages/index.html b/src/pages/index.html index fd5f326a..808227e7 100644 --- a/src/pages/index.html +++ b/src/pages/index.html @@ -45,7 +45,7 @@

Loading...

- [ver5.1] + [ver6.0] diff --git a/src/pages/versions.html b/src/pages/versions.html index 5d0a67ae..23fafeff 100644 --- a/src/pages/versions.html +++ b/src/pages/versions.html @@ -209,6 +209,19 @@

Version 5.1 - 16.07.2018


+
+

Version 6.0 - 12.09.2018

+

+ I like breaking things because my code is bad, so woop, version 6.0 is here. There are a lot of changes in this version like changing the + name of some database tables in the background to make more sense, as well as actually restructuring the API routes to not be horribly + structured. In addition to this, some modules this website uses to run have been replaced with more lightweight ones. For the changes + that actually affect the person using the page, there is now a "crazy mode". This mode makes it so that whenever someone that is currently + viewing the page presses a sound on the main page or soundboard while you have this mode enabled the same sound that played for them played + for you -- and this applies to every person clicking. If there were 100 people clicking different buttons, you would hear 100 sounds playing, + thus I dubbed it "crazy mode". There's also a newly documented sounds endpoint to get info on all available sounds (see GitHub repo Wiki) +

+
+
diff --git a/src/server.js b/src/server.js index 4ec0505c..1043518d 100644 --- a/src/server.js +++ b/src/server.js @@ -145,15 +145,18 @@ http.listen(config.port, () => { server.get('/api/conInfo', (req, res) => res.json({ port: config.port, ssl: config.SSLproxy })); +server.get('/api/counter', (req, res) => { + return res.json({ counter }); +}); + server.get('/api/sounds', (req, res) => { // eslint-disable-line complexity let requestedSounds = sounds; if (['source', 'over', 'under', 'equals'].some(parameter => Object.keys(req.query).includes(parameter))) { - const equals = req.query.equals ? parseInt(req.query.equals) : null; - const over = req.query.over ? parseInt(req.query.over) : null; - const under = req.query.under ? parseInt(req.query.under) : null; + const [equals, over, under] = [parseInt(req.query.equals), parseInt(req.query.over), parseInt(req.query.under)]; - if ((equals && isNaN(equals)) || (over && isNaN(over)) || (under && isNaN(under))) { + if ((req.query.equals && isNaN(equals)) || (req.query.over && isNaN(over)) || (req.query.under && isNaN(under))) { + // Check if the param was initially supplied, and if it was if the input wasn't a number return res.status(400).json({ code: 400, name: 'Invalid range', message: 'The "over", "under" and "equals" parameters must be numbers.' }); } @@ -176,10 +179,6 @@ server.get('/api/sounds', (req, res) => { // eslint-disable-line complexity return res.json(requestedSounds); }); -server.get('/api/counter', (req, res) => { - return res.json({ counter }); -}); - server.get('/api/statistics', (req, res) => { // eslint-disable-line complexity let requestedStats = statistics; const dateRegex = new RegExp(/^(\d{4})-(\d{2})-(\d{2})$/); @@ -192,11 +191,8 @@ server.get('/api/statistics', (req, res) => { // eslint-disable-line complexity return res.status(400).json({ code: 400, name: 'Wrong Format', message: 'Dates must be provided in YYYY-MM-DD format.' }); } - const to = req.query.to; - const from = req.query.from; - const equals = req.query.equals ? parseInt(req.query.equals) : null; - const over = req.query.over ? parseInt(req.query.over) : null; - const under = req.query.under ? parseInt(req.query.under) : null; + const { to, from } = req.query; + const [equals, over, under] = [parseInt(req.query.equals), parseInt(req.query.over), parseInt(req.query.under)]; if ((to && dateFns.isAfter(to, latestStatDate)) || (from && dateFns.isAfter(from, latestStatDate))) { return res.status(400).json({ code: 400, name: 'Invalid timespan', message: 'Dates may not be in the future.' }); @@ -206,7 +202,8 @@ server.get('/api/statistics', (req, res) => { // eslint-disable-line complexity return res.status(400).json({ code: 400, name: 'Invalid timespan', message: 'The start date must be before the end date.' }); } - if ((equals && isNaN(equals)) || (over && isNaN(over)) || (under && isNaN(under))) { + if ((req.query.equals && isNaN(equals)) || (req.query.over && isNaN(over)) || (req.query.under && isNaN(under))) { + // Check if the param was initially supplied, and if it was if the input wasn't a number return res.status(400).json({ code: 400, name: 'Invalid range', message: 'The "over", "under" and "equals" parameters must be numbers.' }); }