2021-03-27 03:56:34 +13:00
|
|
|
const fetch = require("node-fetch")
|
2021-03-26 00:17:04 +13:00
|
|
|
const vm = require("vm")
|
|
|
|
|
|
|
|
class ScriptExecutor {
|
2021-03-27 03:56:34 +13:00
|
|
|
constructor(body) {
|
|
|
|
this.script = new vm.Script(body.script)
|
|
|
|
this.context = vm.createContext(body.context)
|
|
|
|
this.context.fetch = fetch
|
2021-03-26 00:17:04 +13:00
|
|
|
}
|
|
|
|
|
|
|
|
execute() {
|
2021-05-12 04:49:26 +12:00
|
|
|
return this.script.runInContext(this.context)
|
2021-03-26 00:17:04 +13:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-04 20:55:14 +12:00
|
|
|
exports.execute = async function (ctx) {
|
2021-03-27 03:56:34 +13:00
|
|
|
const executor = new ScriptExecutor(ctx.request.body)
|
2021-03-26 00:17:04 +13:00
|
|
|
|
2021-05-12 04:49:26 +12:00
|
|
|
ctx.body = executor.execute()
|
|
|
|
}
|
|
|
|
|
2021-05-12 04:50:26 +12:00
|
|
|
exports.save = async function (ctx) {
|
2021-05-12 04:49:26 +12:00
|
|
|
ctx.throw(501, "Not currently implemented")
|
2021-03-26 00:17:04 +13:00
|
|
|
}
|