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) => { return new Promise((resolve, reject) => {
exec(cmd, (error, stdout, stderr) => { exec(cmd, (error, stdout, stderr) => {
if (error) { if (error) {
console.warn(error); console.warn(error)
} }
resolve(stdout ? stdout : stderr); stdout ? resolve(stdout) : reject(stderr)
}); })
}); })
} }

View File

@ -71,14 +71,16 @@ AUTH.post('/login', (req, res) => {
AUTH.get('/captcha', async (req, res) => { AUTH.get('/captcha', async (req, res) => {
const captcha = crypto.randomBytes(3).toString('hex') 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()
// Make it valid for 10 minutes // Send the captcha image
valid[captcha] = new Date() res.contentType('image/png')
.sendFile('captcha.png', { root: './' })
// Send the captcha image })
res.contentType('image/png') .catch(() => res.status(501).send("ERROR! Failed to generate captcha."))
.sendFile('captcha.png', { root: './' })
}) })