Add captcha logger to captcha/audio
This commit is contained in:
parent
91c02c9b66
commit
9ddbad9bfb
@ -1,9 +1,12 @@
|
||||
import loggerFactory from '@rondo.dev/logger'
|
||||
import { Request, Response } from 'express'
|
||||
import SVGCaptcha from 'svg-captcha'
|
||||
import { Command, ReadableProcess, ReadableWritable, run } from './run'
|
||||
import { TextStream } from './TextStream'
|
||||
import { createCaptcha } from './Captcha'
|
||||
|
||||
const logger = loggerFactory.getLogger('captcha')
|
||||
|
||||
export interface AudioConfig {
|
||||
commands: Command[]
|
||||
size: number
|
||||
@ -18,14 +21,22 @@ export const audio = (config: AudioConfig) => async (
|
||||
req.session!.captcha = createCaptcha(captcha, 'audio')
|
||||
let speech: ReadableProcess
|
||||
try {
|
||||
speech = await speak('test', commands)
|
||||
speech = await speak(captcha, commands)
|
||||
} catch (err) {
|
||||
res.status(500)
|
||||
logger.error('Error generating speech: %s', err.stack)
|
||||
res.status(200)
|
||||
res.send('Internal server error')
|
||||
return
|
||||
}
|
||||
res.status(200)
|
||||
res.header('Cache-control', 'no-cache')
|
||||
res.type(speech.contentType)
|
||||
speech.stdout.pipe(res)
|
||||
logger.info('piping output')
|
||||
speech.stdout.pipe(res, { end: false })
|
||||
speech.stdout.on('end', () => {
|
||||
logger.info('end')
|
||||
res.end()
|
||||
})
|
||||
}
|
||||
|
||||
export async function speak(
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
export function espeak() {
|
||||
return {
|
||||
cmd: 'espeak',
|
||||
args: ['-k', '2', '-s', '90', '--stdin', '--stdout'],
|
||||
contentType: 'audio/wav',
|
||||
}
|
||||
}
|
||||
|
||||
export function opus() {
|
||||
return {
|
||||
cmd: 'opusenc',
|
||||
args: ['-', '-'],
|
||||
contentType: 'audio/opus',
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,7 @@ export const image = (config: ImageConfig) => (req: Request, res: Response) => {
|
||||
size: config.size,
|
||||
})
|
||||
req.session!.captcha = createCaptcha(text, 'image')
|
||||
res.header('Cache-control', 'no-cache')
|
||||
res.type('svg')
|
||||
res.status(200)
|
||||
res.send(data)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user