mirror of
https://github.com/chaos-zhu/easynode.git
synced 2026-10-07 16:37:58 +08:00
- 统一controller方法,使用{res}/ {res, request}参数,移除非必要的uid参数和package-lock.json文件
- 将"执行模式"改为"编码方式",避免与"脚本执行开关"(手动/自动)产生歧义
- 在脚本编辑器中新增同样的编码方式选择功能
- 修复footerbar传递的执行脚本没有判断useBase64问题
- 修复全屏状态下规则编辑对话框、颜色选择器、以及所有下拉菜单不显示的问题,现在使用Teleport将规则编辑对话框动态挂载到全屏的document.fullscreenElement中,原来的下拉菜单和颜色选择器默认也会用 teleport 挂到 body,需要设置:teleported="false"以禁用
80 lines
2.4 KiB
JavaScript
80 lines
2.4 KiB
JavaScript
const { TerminalConfigDB } = require('../utils/db-class')
|
|
|
|
// 终端默认配置
|
|
const DEFAULT_TERMINAL_CONFIG = {
|
|
themeName: 'Afterglow',
|
|
fontFamily: 'monospace', // 使用多平台通用的等宽字体
|
|
fontSize: 16,
|
|
fontColor: '', // 使用主题字体颜色
|
|
cursorColor: '', // 使用主题光标颜色
|
|
selectionColor: '#264f78', // 深蓝色选中颜色,适合深色主题
|
|
background: '', // 使用主题背景
|
|
keywordHighlight: true,
|
|
highlightDebugMode: false,
|
|
customHighlightRules: null, // null表示使用默认规则
|
|
autoExecuteScript: false, // 脚本执行模式
|
|
autoReconnect: false, // 自动重连
|
|
autoShowContextMenu: true // 选中文本后自动显示右键菜单
|
|
}
|
|
|
|
const terminalConfigDB = new TerminalConfigDB().getInstance()
|
|
|
|
// 获取用户的终端配置
|
|
async function getTerminalConfig({ res }) {
|
|
try {
|
|
// 查找用户配置
|
|
let userConfig = await terminalConfigDB.findOneAsync({ isDefault: { $ne: true } })
|
|
|
|
if (!userConfig) {
|
|
// 如果没有用户配置,直接返回默认配置
|
|
userConfig = DEFAULT_TERMINAL_CONFIG
|
|
} else {
|
|
// 合并默认配置和用户配置
|
|
userConfig = {
|
|
...DEFAULT_TERMINAL_CONFIG,
|
|
...userConfig // 用户配置覆盖默认配置
|
|
}
|
|
}
|
|
|
|
res.success({ data: userConfig })
|
|
} catch (error) {
|
|
console.error('Error in getTerminalConfig:', error)
|
|
res.fail({ msg: '服务器内部错误,请稍后重试' })
|
|
}
|
|
}
|
|
|
|
// 保存用户的终端配置
|
|
async function saveTerminalConfig({ res, request }) {
|
|
const { isDefault, name, _id, createTime, ...configData } = request.body
|
|
|
|
try {
|
|
const existingConfig = await terminalConfigDB.findOneAsync({ isDefault: { $ne: true } })
|
|
|
|
const updateData = {
|
|
...configData,
|
|
updateTime: new Date().toISOString()
|
|
}
|
|
|
|
if (existingConfig) {
|
|
// 更新现有配置
|
|
await terminalConfigDB.updateAsync(
|
|
{ _id: existingConfig._id },
|
|
{ $set: updateData }
|
|
)
|
|
} else {
|
|
// 创建新配置
|
|
updateData.createTime = new Date().toISOString()
|
|
await terminalConfigDB.insertAsync(updateData)
|
|
}
|
|
|
|
res.success({ msg: '配置保存成功' })
|
|
} catch (error) {
|
|
console.error('Error in saveTerminalConfig:', error)
|
|
res.fail({ msg: '服务器内部错误,请稍后重试' })
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
getTerminalConfig,
|
|
saveTerminalConfig
|
|
} |