You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.3 KiB
49 lines
1.3 KiB
import tokenHandler from './../../handler/token.js'
|
|
import flowHandler from './../../handler/flow.js'
|
|
import logger from './../../helper/logger.js'
|
|
|
|
/**
|
|
* handle webhook
|
|
*
|
|
* @author Björn Hase <me@herr-hase.wtf>
|
|
* @license hhttps://www.gnu.org/licenses/gpl-3.0.en.html GPL-3
|
|
* @link https://git.node001.net/HerrHase/signpost.git
|
|
*
|
|
*/
|
|
|
|
export default async function(fastify, options) {
|
|
|
|
fastify.addHook('preHandler', flowHandler)
|
|
fastify.addHook('preHandler', tokenHandler)
|
|
|
|
/**
|
|
*
|
|
*
|
|
* @param {object} request
|
|
* @param {object} response
|
|
*
|
|
*/
|
|
fastify.post('/:uuid(^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$)', async function (request, response) {
|
|
|
|
if (response.locals.schema && !request.validateInput(request.body, response.locals.schema)) {
|
|
return response
|
|
.code(400)
|
|
.send()
|
|
}
|
|
|
|
// running actions
|
|
const action = new response.locals.action.default(response.locals.flow, request.body)
|
|
|
|
response
|
|
.code(204)
|
|
.send()
|
|
|
|
// try run from action
|
|
try {
|
|
await action.run()
|
|
} catch(error) {
|
|
logger(response.locals.flow.uuid).error('webhook / run / ' + error)
|
|
}
|
|
})
|
|
}
|