Smol refactor.

This commit is contained in:
BurnyLlama 2022-01-22 21:35:53 +01:00
parent 2af34eb35f
commit 90c099f497
2 changed files with 14 additions and 12 deletions

View File

@ -4,9 +4,9 @@ export default function execawait(cmd) {
return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => {
if (error) {
console.warn(error);
console.warn(error)
}
resolve(stdout ? stdout : stderr);
});
});
stdout ? resolve(stdout) : reject(stderr)
})
})
}

View File

@ -71,8 +71,8 @@ AUTH.post('/login', (req, res) => {
AUTH.get('/captcha', async (req, res) => {
const captcha = crypto.randomBytes(3).toString('hex')
await execawait(`./captcha.sh ${captcha} > captcha.png`)
execawait(`./captcha.sh ${captcha} > captcha.png`)
.then(() => {
// Make it valid for 10 minutes
valid[captcha] = new Date()
@ -80,6 +80,8 @@ AUTH.get('/captcha', async (req, res) => {
res.contentType('image/png')
.sendFile('captcha.png', { root: './' })
})
.catch(() => res.status(501).send("ERROR! Failed to generate captcha."))
})
export default AUTH