From 04edd97967f135d8f92b3efd8894e8e23907908f Mon Sep 17 00:00:00 2001 From: whyour Date: Fri, 21 Jul 2023 21:22:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20node=20=E4=BE=9D=E8=B5=96?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/public.ts | 2 +- back/services/dependence.ts | 24 +++++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/back/public.ts b/back/public.ts index d9eb1cc7..094c99ea 100644 --- a/back/public.ts +++ b/back/public.ts @@ -13,7 +13,7 @@ const client = new HealthClient( app.get('/api/health', (req, res) => { client.check({ service: 'cron' }, (err, response) => { if (err) { - return res.status(500).send({ code: 500, error: err }); + return res.status(200).send({ code: 500, error: err }); } return res.status(200).send({ code: 200, data: response }); }); diff --git a/back/services/dependence.ts b/back/services/dependence.ts index af70bb0b..70bf920b 100644 --- a/back/services/dependence.ts +++ b/back/services/dependence.ts @@ -168,7 +168,7 @@ export default class DependenceService { const socketMessageType = isInstall ? 'installDependence' : 'uninstallDependence'; - const depName = dependency.name.trim(); + let depName = dependency.name.trim(); const depRunCommand = ( isInstall ? InstallDependenceCommandTypes @@ -191,29 +191,35 @@ export default class DependenceService { if (isInstall) { const getCommandPrefix = GetDependenceCommandTypes[dependency.type]; const depVersionStr = versionDependenceCommandTypes[dependency.type]; - const [_depName, _depVersion] = dependency.name - .trim() - .split(depVersionStr); + let depVersion = ''; + if (depName.includes(depVersionStr)) { + const symbolRegx = new RegExp(`(.*)${depVersionStr}([0-9\\.\\-\\+a-zA-Z]*)`); + const [, _depName, _depVersion] = depName.match(symbolRegx) || []; + if (_depVersion && _depName) { + depName = _depName; + depVersion = _depVersion; + } + } const isNodeDependence = dependency.type === DependenceTypes.nodejs; const isLinuxDependence = dependency.type === DependenceTypes.linux; const isPythonDependence = dependency.type === DependenceTypes.python3; const depInfo = ( await promiseExecSuccess( isNodeDependence - ? `${getCommandPrefix} | grep "${_depName}" | head -1` - : `${getCommandPrefix} ${_depName}`, + ? `${getCommandPrefix} | grep "${depName}" | head -1` + : `${getCommandPrefix} ${depName}`, ) ).replace(/\s{2,}/, ' '); if ( depInfo && - ((isNodeDependence && depInfo.split(' ')?.[0] === _depName) || + ((isNodeDependence && depInfo.split(' ')?.[0] === depName) || (isLinuxDependence && depInfo.toLocaleLowerCase().includes('installed')) || isPythonDependence) && - (!_depVersion || depInfo.includes(_depVersion)) + (!depVersion || depInfo.includes(depVersion)) ) { const endTime = dayjs(); - const _message = `检测到已经安装 ${_depName}\n\n${depInfo}\n跳过安装\n\n依赖${actionText}成功,结束时间 ${endTime.format( + const _message = `检测到已经安装 ${depName}\n\n${depInfo}\n跳过安装\n\n依赖${actionText}成功,结束时间 ${endTime.format( 'YYYY-MM-DD HH:mm:ss', )},耗时 ${endTime.diff(startTime, 'second')} 秒`; this.sockService.sendMessage({