mirror of
https://github.com/fofolee/uTools-quickcommand.git
synced 2025-06-09 15:04:06 +08:00
微调
This commit is contained in:
parent
7c32de1bbc
commit
1a3c9325a2
@ -325,7 +325,7 @@ let modWindowHeight = height => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 屏蔽危险函数
|
// 屏蔽危险函数
|
||||||
var getuToolsLite = () => {
|
let getuToolsLite = () => {
|
||||||
var utoolsLite = Object.assign({}, utools)
|
var utoolsLite = Object.assign({}, utools)
|
||||||
delete utoolsLite.db
|
delete utoolsLite.db
|
||||||
delete utoolsLite.removeFeature
|
delete utoolsLite.removeFeature
|
||||||
@ -333,7 +333,7 @@ var getuToolsLite = () => {
|
|||||||
return utoolsLite
|
return utoolsLite
|
||||||
}
|
}
|
||||||
|
|
||||||
var getSandboxFuns = () => {
|
let getSandboxFuns = () => {
|
||||||
var sandbox = {
|
var sandbox = {
|
||||||
utools: getuToolsLite(),
|
utools: getuToolsLite(),
|
||||||
quickcommand: quickcommand,
|
quickcommand: quickcommand,
|
||||||
@ -352,7 +352,7 @@ var getSandboxFuns = () => {
|
|||||||
return sandbox
|
return sandbox
|
||||||
}
|
}
|
||||||
|
|
||||||
runCodeInVm = (cmd, cb, payload = "") => {
|
let createNodeVM = (payload = "") => {
|
||||||
var sandbox = getSandboxFuns()
|
var sandbox = getSandboxFuns()
|
||||||
sandbox.quickcommand.payload = payload
|
sandbox.quickcommand.payload = payload
|
||||||
const vm = new NodeVM({
|
const vm = new NodeVM({
|
||||||
@ -364,32 +364,36 @@ runCodeInVm = (cmd, cb, payload = "") => {
|
|||||||
env: process.env,
|
env: process.env,
|
||||||
sandbox: sandbox,
|
sandbox: sandbox,
|
||||||
});
|
});
|
||||||
|
return vm
|
||||||
|
}
|
||||||
|
|
||||||
var parseItem = item => {
|
let parseItem = item => {
|
||||||
if (typeof (item) == "object") {
|
if (typeof (item) == "object") {
|
||||||
if (Buffer.isBuffer(item)) {
|
if (Buffer.isBuffer(item)) {
|
||||||
var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`
|
var bufferString = `[Buffer ${item.slice(0, 50).toString('hex').match(/\w{1,2}/g).join(" ")}`
|
||||||
if (item.length > 50) bufferString += `... ${(item.length / 1000).toFixed(2)}kb`
|
if (item.length > 50) bufferString += `... ${(item.length / 1000).toFixed(2)}kb`
|
||||||
return bufferString + ']'
|
return bufferString + ']'
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
var cache = [];
|
var cache = [];
|
||||||
var string = JSON.stringify(item, (key, value) => {
|
var string = JSON.stringify(item, (key, value) => {
|
||||||
if (typeof value === 'object' && value !== null) {
|
if (typeof value === 'object' && value !== null) {
|
||||||
if (cache.indexOf(value) !== -1) return
|
if (cache.indexOf(value) !== -1) return
|
||||||
cache.push(value);
|
cache.push(value);
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}, '\t')
|
}, '\t')
|
||||||
if (string != "{}") return string
|
if (string != "{}") return string
|
||||||
} catch (error) { }
|
} catch (error) { }
|
||||||
}
|
|
||||||
} else if (typeof (item) == "undefined") {
|
|
||||||
return "undefined"
|
|
||||||
}
|
}
|
||||||
return item.toString()
|
} else if (typeof (item) == "undefined") {
|
||||||
|
return "undefined"
|
||||||
}
|
}
|
||||||
|
return item.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
runCodeInVm = (cmd, cb, payload = "") => {
|
||||||
|
const vm = createNodeVM(payload)
|
||||||
//重定向 console
|
//重定向 console
|
||||||
vm.on('console.log', stdout => {
|
vm.on('console.log', stdout => {
|
||||||
console.log(stdout);
|
console.log(stdout);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user