Skip to content

Commit

Permalink
Third time's the charm
Browse files Browse the repository at this point in the history
  • Loading branch information
robflop committed Sep 12, 2018
1 parent 17a33b0 commit 8905a3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<p id="counter">Loading...</p>
<!--Display placeholder-->
<button id="button">やめろ!!</button>
<a href="versions" id="version" class="mobile-scale">[ver5.1]</a>
<a href="versions" id="version" class="mobile-scale">[ver6.0]</a>
<!--Share buttons-->
<span id="share-buttons-frame">
<span class="share-buttons"><a href="https://twitter.com/intent/tweet?text=Megumin%20Fansite%21%20Check%20it%20out%21&amp;via=robflop98&amp;url=https%3A%2F%2Fmegumin.love" onclick="window.open(this.href, '', 'width=650, height=450, menubar=no, toolbar=no, scrollbars=yes'); return false; ">
Expand Down
13 changes: 13 additions & 0 deletions src/pages/versions.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,19 @@ <h2>Version 5.1 - 16.07.2018</h2>
</p>
</div>
<hr>
<div class="version-box">
<h2>Version 6.0 - 12.09.2018</h2>
<p>
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)
</p>
</div>
<hr>
<div id="backlink-bottom">
<a class="backlink" href="/">Back</a>
</div>
Expand Down
25 changes: 11 additions & 14 deletions src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.' });
}

Expand All @@ -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})$/);
Expand All @@ -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.' });
Expand All @@ -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.' });
}

Expand Down

0 comments on commit 8905a3c

Please sign in to comment.