Compact code

This commit is contained in:
CataIana 2021-02-03 19:36:14 +11:00
parent ff1e6d323c
commit e5f37bd3b6

View file

@ -179,24 +179,10 @@ app.get('/:templateName/', async (req, res) => {
if (!/^https?:/.test(req.query.url)) { if (!/^https?:/.test(req.query.url)) {
return res.status(400).end('Invalid url!'); return res.status(400).end('Invalid url!');
} }
let direction = null; let direction = req.query.reverse === 'true' ? '\\' : '/';
if (req.query.reverse) {
if (req.query.reverse == 'false') {
direction = '/';
} else if (req.query.reverse == 'true') {
direction = '\\';
} else {
res.status(404).end();
}
} else {
direction = '/';
}
console.log('Got command ', direction, req.params.templateName, direction === '\\' ? 'flipped' : 'not flipped', req.query.url); 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); result = new ImageEx(req.query.url);
await result.loaded; // eslint-disable-line no-await-in-loop await result.loaded; // eslint-disable-line no-await-in-loop
}
const templateData = templates[req.params.templateName]; const templateData = templates[req.params.templateName];
all(templateData, template => { // eslint-disable-line no-loop-func all(templateData, template => { // eslint-disable-line no-loop-func
result = render(template, result, null, direction === '\\'); result = render(template, result, null, direction === '\\');
@ -205,7 +191,7 @@ app.get('/:templateName/', async (req, res) => {
return result.export(res); return result.export(res);
} catch (err) { } catch (err) {
console.log(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 => { 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); let commandParsed = /^([/\\])(\w+)\b/.exec(message.cleanContent);
if (commandParsed) { if (commandParsed) {
const [, direction, command] = commandParsed; const [, direction, command] = commandParsed;