From e5f37bd3b66d783e0a5dd81bcfbf03cd0767d098 Mon Sep 17 00:00:00 2001 From: CataIana Date: Wed, 3 Feb 2021 19:36:14 +1100 Subject: [PATCH] Compact code --- index.js | 33 ++++++++------------------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/index.js b/index.js index 04257d1..4d2e7db 100644 --- a/index.js +++ b/index.js @@ -179,33 +179,19 @@ app.get('/:templateName/', async (req, res) => { if (!/^https?:/.test(req.query.url)) { return res.status(400).end('Invalid url!'); } - let direction = null; - if (req.query.reverse) { - if (req.query.reverse == 'false') { - direction = '/'; - } else if (req.query.reverse == 'true') { - direction = '\\'; - } else { - res.status(404).end(); - } - } else { - direction = '/'; - } + let direction = req.query.reverse === 'true' ? '\\' : '/'; console.log('Got command ', direction, req.params.templateName, direction === '\\' ? 'flipped' : 'not flipped', req.query.url); - let result = null; - if (result === null) { - result = new ImageEx(req.query.url); - await result.loaded; // eslint-disable-line no-await-in-loop - } - const templateData = templates[req.params.templateName]; - all(templateData, template => { // eslint-disable-line no-loop-func - result = render(template, result, null, direction === '\\'); - }); + result = new ImageEx(req.query.url); + await result.loaded; // eslint-disable-line no-await-in-loop + const templateData = templates[req.params.templateName]; + all(templateData, template => { // eslint-disable-line no-loop-func + result = render(template, result, null, direction === '\\'); + }); return result.export(res); } catch (err) { console.log(err); - return res.status(400).end(err.message); + return res.status(400).end({'error': err.message}); } }); @@ -297,9 +283,6 @@ const otherCommands = { client.on('message', async message => { - console.log(`[${message.guild.name} - ${message.channel.name}] ${message.author.username}` - + `#${message.author.discriminator}: ${message.cleanContent}`); - let commandParsed = /^([/\\])(\w+)\b/.exec(message.cleanContent); if (commandParsed) { const [, direction, command] = commandParsed;