Smol refactor.
This commit is contained in:
parent
2af34eb35f
commit
90c099f497
|
@ -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)
|
||||||
});
|
})
|
||||||
});
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -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: './' })
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user