feat: 封装 enterData, 命令图标改进

This commit is contained in:
lee
2020-10-15 21:52:52 +08:00
parent 60968ac334
commit 9e8e0287b0
3 changed files with 25 additions and 28 deletions

View File

@@ -440,9 +440,10 @@ let getSandboxFuns = () => {
return sandbox
}
let createNodeVM = (payload = "") => {
let createNodeVM = (enterData = {}) => {
var sandbox = getSandboxFuns()
sandbox.quickcommand.payload = payload
sandbox.quickcommand.enterData = enterData
sandbox.quickcommand.payload = enterData.payload
const vm = new NodeVM({
require: {
external: true,
@@ -488,8 +489,8 @@ let parseItem = item => {
return item.toString()
}
runCodeInVm = (cmd, cb, payload = "") => {
const vm = createNodeVM(payload)
runCodeInVm = (cmd, cb, enterData = {}) => {
const vm = createNodeVM(enterData)
//重定向 console
vm.on('console.log', stdout => {
console.log(stdout);
@@ -596,7 +597,7 @@ dirPythonMod = (mod, cb) => {
getNodeJsCommand = () => {
var obj = getSandboxFuns()
obj.Buffer = Buffer
obj.quickcommand.payload = ''
obj.quickcommand.enterData = {code: '', type: '', payload: ''}
return obj
}
@@ -621,9 +622,14 @@ getQuickCommandScriptFile = ext => {
return path.join(os.tmpdir(), `QuickCommandTempScript.${ext}`)
}
getBase64Ico = async path => {
let sourceImage = 'data:image/png;base64,' + fs.readFileSync(path, 'base64')
let compressedImage = await getCompressedIco(path)
getBase64Ico = async filepath => {
let sourceImage, ext = path.extname(filepath).slice(1)
if (ext == 'png' || ext == 'jpg' || ext == 'jpeg' || ext == 'bmp' || ext == 'ico') {
sourceImage = `data:image/${ext};base64,` + fs.readFileSync(filepath, 'base64')
} else {
sourceImage = utools.getFileIcon(filepath)
}
let compressedImage = await getCompressedIco(sourceImage)
return compressedImage.length > sourceImage.length ? sourceImage : compressedImage
}