mirror of
https://github.com/chaos-zhu/easynode.git
synced 2026-05-11 07:46:54 +08:00
- 新增终端高亮系统,支持8类规则自动识别关键信息 - 使用正则表达式合并算法,终端所有的文本块输出只需要1-2次正则匹配即可,不影响实时的输出速度 - 高亮设置支持实时预览和规则导入导出 - 重构终端配置管理,提供模块化的终端设置界面,分为三部分:基础设置、高亮设置和其他设置,其中基础设置包含原来的的本地设置/终端设置内容,其他设置包含原来的本地设置/快捷操作内容,高亮设置为新增 - 新增TerminalConfigDB类,所有的终端设置使用数据库持久化管理 - 修复终端主题定制中的半透明灰色图层遮盖问题,保证终端背景颜色和效果颜色一致性,支持各种终端内容的深度定制,包括字体、字体大小、字体颜色、光标颜色、选中颜色等,新增了更多预设背景色 - 脚本库中新增执行模式选项,用户可以选择使用直接运行或者base64编码处理后运行,以支持复杂的多行脚本运行问题和灵活管理 - 增强sftp组件,支持sftp窗口宽度拖拽改变,个性化显示文件信息列(大小、修改时间、权限、拥有者)
76 lines
2.6 KiB
JavaScript
76 lines
2.6 KiB
JavaScript
const path = require('path')
|
|
const decryptAndExecuteAsync = require('../utils/decrypt-file')
|
|
const { randomStr } = require('../utils/tools')
|
|
const { ScriptsDB } = require('../utils/db-class')
|
|
const localShellJson = require('../config/shell.json')
|
|
const scriptsDB = new ScriptsDB().getInstance()
|
|
|
|
let localShell = JSON.parse(JSON.stringify(localShellJson)).map((item) => {
|
|
return { ...item, id: randomStr(10), index: '--', description: item.description, group: 'builtin' }
|
|
})
|
|
|
|
async function getScriptList({ res }) {
|
|
let data = await scriptsDB.findAsync({})
|
|
data = data.map(item => {
|
|
return { ...item, id: item._id, group: item.group || 'default' }
|
|
})
|
|
data?.sort((a, b) => Number(b.index || 0) - Number(a.index || 0))
|
|
data.push(...localShell)
|
|
res.success({ data })
|
|
}
|
|
|
|
async function getLocalScriptList({ res }) {
|
|
res.success({ data: localShell })
|
|
}
|
|
|
|
const addScript = async ({ res, request }) => {
|
|
// useBase64 默认为false
|
|
let { body: { name, description, command, index, group, useBase64 = false } } = request
|
|
if (!name || !command) return res.fail({ data: false, msg: '参数错误' })
|
|
index = Number(index) || 0
|
|
let record = { name, description, command, index, group, useBase64 }
|
|
await scriptsDB.insertAsync(record)
|
|
res.success({ data: '添加成功' })
|
|
}
|
|
|
|
const updateScriptList = async ({ res, request }) => {
|
|
let { params: { id } } = request
|
|
// useBase64 默认为false
|
|
let { body: { name, description, command, index, group, useBase64 = false } } = request
|
|
if (!name || !command) return res.fail({ data: false, msg: '参数错误' })
|
|
await scriptsDB.updateAsync({ _id: id }, { name, description, command, index, group, useBase64 })
|
|
res.success({ data: '修改成功' })
|
|
}
|
|
|
|
const removeScript = async ({ res, request }) => {
|
|
let { params: { id } } = request
|
|
await scriptsDB.removeAsync({ _id: id })
|
|
res.success({ data: '移除成功' })
|
|
}
|
|
|
|
const batchRemoveScript = async ({ res, request }) => {
|
|
let { body: { ids } } = request
|
|
if (!Array.isArray(ids)) return res.fail({ msg: '参数错误' })
|
|
const numRemoved = await scriptsDB.removeAsync({ _id: { $in: ids } }, { multi: true })
|
|
res.success({ data: `批量移除成功,数量: ${ numRemoved }` })
|
|
}
|
|
|
|
const importScript = async ({ res, request }) => {
|
|
let { impScript } = (await decryptAndExecuteAsync(path.join(__dirname, 'plus.js'))) || {}
|
|
if (impScript) {
|
|
await impScript({ res, request })
|
|
} else {
|
|
return res.fail({ data: false, msg: 'Plus专属功能!' })
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
addScript,
|
|
getScriptList,
|
|
getLocalScriptList,
|
|
updateScriptList,
|
|
removeScript,
|
|
batchRemoveScript,
|
|
importScript
|
|
}
|