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