From a05056df32ee4388237fc018746a09a47633dd2f Mon Sep 17 00:00:00 2001 From: chaos-zhu Date: Wed, 31 Jul 2024 18:44:46 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20=E5=86=85=E7=BD=AE=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E5=AE=89=E8=A3=85=E8=84=9A=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/app/controller/host.js | 2 +- server/app/db.js | 30 +++++++++++++++++++++ server/app/utils/storage.js | 2 +- web/src/views/group/index.vue | 46 ++++++++++++++++++++++++++------- web/src/views/scripts/index.vue | 12 ++++----- 5 files changed, 75 insertions(+), 17 deletions(-) diff --git a/server/app/controller/host.js b/server/app/controller/host.js index 873cfae..b3b9f86 100644 --- a/server/app/controller/host.js +++ b/server/app/controller/host.js @@ -6,7 +6,7 @@ async function getHostList({ res }) { data?.sort((a, b) => Number(b.index || 0) - Number(a.index || 0)) for (const item of data) { let { username, port, authType, _id: id, credential } = item - console.log('解密凭证title: ', credential) + // console.log('解密凭证title: ', credential) if (credential) credential = await AESDecryptSync(credential) const isConfig = Boolean(username && port && (item[authType])) Object.assign(item, { id, isConfig, password: '', privateKey: '', credential }) diff --git a/server/app/db.js b/server/app/db.js index 4a9f993..b6359f9 100644 --- a/server/app/db.js +++ b/server/app/db.js @@ -1,5 +1,6 @@ const { writeKey, writeNotifyList, writeGroupList } = require('./utils/storage') const { KeyDB, NotifyDB, GroupDB, EmailNotifyDB } = require('./utils/db-class') +const { readScriptList, writeScriptList } = require('./utils') function initKeyDB() { return new Promise((resolve, reject) => { @@ -145,9 +146,38 @@ function initEmailNotifyDB() { }) }) } + +function initScriptsDB() { + // eslint-disable-next-line no-async-promise-executor + return new Promise(async (resolve) => { + let scriptList = await readScriptList() + let clientInstallScript = 'wget https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-instal.sh | bash' + let clientUninstallScript = 'wget https://mirror.ghproxy.com/https://raw.githubusercontent.com/chaos-zhu/easynode/main/client/easynode-client-uninstall.sh | bash' + let clientVersion = process.env.CLIENT_VERSION + consola.info('客户端版本:', clientVersion) + let installId = `clientInstall${ clientVersion }` + let uninstallId = `clientUninstall${ clientVersion }` + + let isClientInstall = scriptList?.find(script => script._id = installId) + let isClientUninstall = scriptList?.find(script => script._id = uninstallId) + let writeFlag = false + if (!isClientInstall) { + scriptList.push({ _id: installId, name: `easynode-client-${ clientVersion }安装脚本`, remark: '系统内置|重启生成', content: clientInstallScript, index: 99 }) + writeFlag = true + } + if (!isClientUninstall) { + scriptList.push({ _id: uninstallId, name: `easynode-client-${ clientVersion }卸载脚本`, remark: '系统内置|重启生成', content: clientUninstallScript, index: 98 }) + writeFlag = true + } + if (writeFlag) await writeScriptList(scriptList) + resolve() + }) +} + module.exports = async () => { await initKeyDB() await initNotifyDB() await initGroupDB() await initEmailNotifyDB() + await initScriptsDB() } \ No newline at end of file diff --git a/server/app/utils/storage.js b/server/app/utils/storage.js index 14683f8..a257fa5 100644 --- a/server/app/utils/storage.js +++ b/server/app/utils/storage.js @@ -253,7 +253,7 @@ const writeScriptList = async (list = []) => { const scriptsDB = new ScriptsDB().getInstance() scriptsDB.remove({}, { multi: true }, (err) => { if (err) { - consola.error('清空group list出错:', err) + consola.error('清空scripts list出错:', err) reject(err) } else { scriptsDB.insert(list, (err, newDocs) => { diff --git a/web/src/views/group/index.vue b/web/src/views/group/index.vue index 4ac43c3..f9550c5 100644 --- a/web/src/views/group/index.vue +++ b/web/src/views/group/index.vue @@ -4,11 +4,16 @@ 添加分组 - + - - + + - + - +