FINALLY fix it
This commit is contained in:
parent
016c1be6d0
commit
2e3b7c2fb2
2 changed files with 18 additions and 26 deletions
39
index.js
39
index.js
|
@ -1,4 +1,4 @@
|
|||
const { Isolate } = require('isolated-vm')
|
||||
const { VM } = require('@n8n/vm2')
|
||||
const { Server } = require('socket.io')
|
||||
const util = require('util')
|
||||
const { stylize } = require('./colors')
|
||||
|
@ -13,10 +13,10 @@ const BRIDGE_PREFIX = 'function:'
|
|||
|
||||
const io = new Server(3069)
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
io.on('connection', async (socket) => {
|
||||
let functions
|
||||
|
||||
let proxy
|
||||
let vm
|
||||
|
||||
const handler = {
|
||||
get (target, prop) {
|
||||
|
@ -49,33 +49,26 @@ io.on('connection', (socket) => {
|
|||
resetVM()
|
||||
})
|
||||
|
||||
const isolate = new Isolate({ memoryLimit: 256 })
|
||||
|
||||
let context
|
||||
async function resetVM () {
|
||||
context = await isolate.createContext()
|
||||
|
||||
// TODO: fix
|
||||
|
||||
// const global = context.global
|
||||
|
||||
// await global.set('this', global.derefInto())
|
||||
// await global.set('global', global.derefInto())
|
||||
|
||||
// await global.set('bridge', () => { return proxy })
|
||||
// await global.set('randomstring', () => randomstring)
|
||||
// await global.set('ChatMessage', () => ChatMessage)
|
||||
// await global.set('mc', () => mc)
|
||||
// await global.set('moment', () => moment)
|
||||
// await global.set('crypto', () => crypto)
|
||||
// await global.set('nbt', () => nbt)
|
||||
vm = new VM({
|
||||
timeout: 1000,
|
||||
sandbox: {
|
||||
get bridge () { return proxy },
|
||||
randomstring,
|
||||
ChatMessage,
|
||||
mc,
|
||||
moment,
|
||||
crypto,
|
||||
nbt
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
resetVM()
|
||||
|
||||
socket.on('runCode', async (transactionId, code) => {
|
||||
try {
|
||||
const output = await context.eval(code, { timeout: 1000 })
|
||||
const output = vm.run(code)
|
||||
|
||||
socket.emit('codeOutput', transactionId, false, util.inspect(output, { stylize }))
|
||||
} catch (e) {
|
||||
|
|
|
@ -10,14 +10,13 @@
|
|||
"author": "",
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"isolated-vm": "^4.6.0",
|
||||
"@n8n/vm2": "^3.9.25",
|
||||
"minecraft-protocol": "^1.43.1",
|
||||
"moment": "^2.29.4",
|
||||
"moment-timezone": "^0.5.43",
|
||||
"prismarine-chat": "^1.8.0",
|
||||
"prismarine-nbt": "^2.2.1",
|
||||
"randomstring": "^1.3.0",
|
||||
"socket.io": "^4.7.1",
|
||||
"vm2": "^3.9.19"
|
||||
"socket.io": "^4.7.1"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue