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 { Request, Response } from 'express'
|
||||||
import SVGCaptcha from 'svg-captcha'
|
import SVGCaptcha from 'svg-captcha'
|
||||||
import { Command, ReadableProcess, ReadableWritable, run } from './run'
|
import { Command, ReadableProcess, ReadableWritable, run } from './run'
|
||||||
import { TextStream } from './TextStream'
|
import { TextStream } from './TextStream'
|
||||||
import { createCaptcha } from './Captcha'
|
import { createCaptcha } from './Captcha'
|
||||||
|
|
||||||
|
const logger = loggerFactory.getLogger('captcha')
|
||||||
|
|
||||||
export interface AudioConfig {
|
export interface AudioConfig {
|
||||||
commands: Command[]
|
commands: Command[]
|
||||||
size: number
|
size: number
|
||||||
@ -18,14 +21,22 @@ export const audio = (config: AudioConfig) => async (
|
|||||||
req.session!.captcha = createCaptcha(captcha, 'audio')
|
req.session!.captcha = createCaptcha(captcha, 'audio')
|
||||||
let speech: ReadableProcess
|
let speech: ReadableProcess
|
||||||
try {
|
try {
|
||||||
speech = await speak('test', commands)
|
speech = await speak(captcha, commands)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
res.status(500)
|
logger.error('Error generating speech: %s', err.stack)
|
||||||
|
res.status(200)
|
||||||
res.send('Internal server error')
|
res.send('Internal server error')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
res.status(200)
|
||||||
|
res.header('Cache-control', 'no-cache')
|
||||||
res.type(speech.contentType)
|
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(
|
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,
|
size: config.size,
|
||||||
})
|
})
|
||||||
req.session!.captcha = createCaptcha(text, 'image')
|
req.session!.captcha = createCaptcha(text, 'image')
|
||||||
|
res.header('Cache-control', 'no-cache')
|
||||||
res.type('svg')
|
res.type('svg')
|
||||||
res.status(200)
|
res.status(200)
|
||||||
res.send(data)
|
res.send(data)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user