limit to one capture at a time
This commit is contained in:
parent
16685771da
commit
7989e38207
|
@ -1,8 +1,17 @@
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
const { spawn } = require('child_process');
|
const { spawn } = require('child_process')
|
||||||
|
|
||||||
|
var capturing = false
|
||||||
|
|
||||||
export default async function handler (req, res) {
|
export default async function handler (req, res) {
|
||||||
|
if (capturing) {
|
||||||
|
return res.writeHead(503, {
|
||||||
|
'Retry-After' : 1
|
||||||
|
}).end()
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
|
capturing = true
|
||||||
const url = process.env.SELF_URL + '/' + path.join(...(req.query.path || []))
|
const url = process.env.SELF_URL + '/' + path.join(...(req.query.path || []))
|
||||||
res.setHeader('Content-Type', 'image/png')
|
res.setHeader('Content-Type', 'image/png')
|
||||||
|
|
||||||
|
@ -16,6 +25,7 @@ export default async function handler (req, res) {
|
||||||
res.status(200).end()
|
res.status(200).end()
|
||||||
}
|
}
|
||||||
capture.removeAllListeners()
|
capture.removeAllListeners()
|
||||||
|
capturing = false
|
||||||
resolve()
|
resolve()
|
||||||
})
|
})
|
||||||
capture.on('error', err => console.log('error', err))
|
capture.on('error', err => console.log('error', err))
|
||||||
|
|
Loading…
Reference in New Issue