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.

56 lines
1.4 KiB

import * as fs from 'fs'
import * as path from 'path'
/**
* getting handlers
*
* @author Björn Hase, me@herr-hase.wtf
* @license http://opensource.org/licenses/MIT The MIT License
* @link https://gitea.node001.net/HerrHase/super-hog
*
*/
export default async function(fastify, opts)
{
fastify.get('/handler/:namespace(request|action)', async function (request, reply)
{
// handlers that found
const handlers = []
// directories to find
const directories = [
'custom',
'handlers'
]
// getting
directories.forEach((directory) => {
// create path
const directoryPath = './../runner/' + directory + '/' + request.params.namespace
// adding each from directory
3 years ago
fs.readdirSync(directoryPath).forEach(file => {
let name = file.replace('.js', '')
// if custom add to name
if (request.params.namespace === 'custom') {
name += ' (custom)'
}
handlers.push({
'name': file.replace('.js', ''),
3 years ago
'className': file,
'file': directoryPath + file
})
})
})
reply
.code(200)
.send({
'data': handlers
})
})
}