From 5db6e7eb68c560bd6b4d47b0294565fd7e69616f Mon Sep 17 00:00:00 2001 From: zhengkunwang <31820853+zhengkunwang223@users.noreply.github.com> Date: Wed, 25 Oct 2023 16:05:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Node.js=20=E8=BF=90=E8=A1=8C=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E4=B9=89=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E5=91=BD=E4=BB=A4=20(#2677)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refs https://github.com/1Panel-dev/1Panel/issues/2559 --- backend/app/service/runtime.go | 18 ++++ frontend/src/lang/modules/en.ts | 2 + frontend/src/lang/modules/tw.ts | 2 + frontend/src/lang/modules/zh.ts | 2 + .../website/runtime/node/operate/index.vue | 84 +++++++++++++------ 5 files changed, 83 insertions(+), 25 deletions(-) diff --git a/backend/app/service/runtime.go b/backend/app/service/runtime.go index c40f01b65..649fbd403 100644 --- a/backend/app/service/runtime.go +++ b/backend/app/service/runtime.go @@ -332,6 +332,24 @@ func (r *RuntimeService) Update(req request.RuntimeUpdate) error { } } } + + appDetail, err := appDetailRepo.GetFirst(commonRepo.WithByID(runtime.AppDetailID)) + if err != nil { + return err + } + app, err := appRepo.GetFirst(commonRepo.WithByID(appDetail.AppId)) + if err != nil { + return err + } + fileOp := files.NewFileOp() + appVersionDir := path.Join(constant.AppResourceDir, app.Resource, app.Key, appDetail.Version) + if !fileOp.Stat(appVersionDir) || appDetail.Update { + if err := downloadApp(app, appDetail, nil); err != nil { + return err + } + _ = fileOp.Rename(path.Join(runtime.GetPath(), "run.sh"), path.Join(runtime.GetPath(), "run.sh.bak")) + _ = fileOp.CopyFile(path.Join(appVersionDir, "run.sh"), runtime.GetPath()) + } } projectDir := path.Join(constant.RuntimeDir, runtime.Type, runtime.Name) diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index b6c3c2405..59d9b78b5 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -1828,6 +1828,8 @@ const message = { module: 'Module', nodeOperatorHelper: 'Is {0} {1} module? The operation may cause abnormality in the operating environment, please confirm before proceeding', + customScript: 'Custom startup command', + customScriptHelper: 'Please fill in the complete startup command, for example: npm run start', }, process: { pid: 'Process ID', diff --git a/frontend/src/lang/modules/tw.ts b/frontend/src/lang/modules/tw.ts index cb6ed5944..46cc75e59 100644 --- a/frontend/src/lang/modules/tw.ts +++ b/frontend/src/lang/modules/tw.ts @@ -1724,6 +1724,8 @@ const message = { moduleManager: '模塊管理', module: '模塊', nodeOperatorHelper: '是否{0} {1} 模組? 操作可能導致運轉環境異常,請確認後操作', + customScript: '自訂啟動指令', + customScriptHelper: '請填寫完整的啟動指令,例如:npm run start', }, process: { pid: '進程ID', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 6cdeba110..08a77c5d0 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -1724,6 +1724,8 @@ const message = { moduleManager: '模块管理', module: '模块', nodeOperatorHelper: '是否{0} {1} 模块?操作可能导致运行环境异常,请确认后操作', + customScript: '自定义启动命令', + customScriptHelper: '请填写完整的启动命令,例如:npm run start', }, process: { pid: '进程ID', diff --git a/frontend/src/views/website/runtime/node/operate/index.vue b/frontend/src/views/website/runtime/node/operate/index.vue index 3cc7a26b0..b5279fad9 100644 --- a/frontend/src/views/website/runtime/node/operate/index.vue +++ b/frontend/src/views/website/runtime/node/operate/index.vue @@ -65,22 +65,45 @@ - - - - - {{ script.name }} - {{ ' 【 ' + script.script + ' 】' }} - - - - {{ $t('runtime.runScriptHelper') }} - + + + + + + + {{ script.name }} + {{ ' 【 ' + script.script + ' 】' }} + + + + + + {{ $t('runtime.runScriptHelper') }} + + + {{ $t('runtime.customScriptHelper') }} + + + + + + + + + @@ -94,13 +117,13 @@ {{ $t('runtime.externalPortHelper') }} - - - - - + @@ -178,6 +201,7 @@ const initData = (type: string) => ({ params: { PACKAGE_MANAGER: 'npm', HOST_IP: '0.0.0.0', + CUSTOM_SCRIPT: '0', }, type: type, resource: 'appstore', @@ -193,12 +217,14 @@ const rules = ref({ codeDir: [Rules.requiredInput], port: [Rules.requiredInput, Rules.paramPort, checkNumberRange(1, 65535)], source: [Rules.requiredSelect], + params: { NODE_APP_PORT: [Rules.requiredInput, Rules.paramPort, checkNumberRange(1, 65535)], PACKAGE_MANAGER: [Rules.requiredSelect], HOST_IP: [Rules.requiredSelect], EXEC_SCRIPT: [Rules.requiredSelect], CONTAINER_NAME: [Rules.requiredInput, Rules.containerName], + CUSTOM_SCRIPT: [Rules.requiredInput], }, }); const scripts = ref([]); @@ -250,6 +276,13 @@ const getPath = (codeDir: string) => { getScripts(); }; +const changeScriptType = () => { + runtime.params['EXEC_SCRIPT'] = ''; + if (runtime.params['CUSTOM_SCRIPT'] == '0') { + getScripts(); + } +}; + const getScripts = () => { GetNodeScripts({ codeDir: runtime.codeDir }).then((res) => { scripts.value = res.data; @@ -359,10 +392,11 @@ const getRuntime = async (id: number) => { port: data.port, }); editParams.value = data.appParams; - if (mode.value == 'edit') { - searchApp(data.appID); + searchApp(data.appID); + if (data.params['CUSTOM_SCRIPT'] == '0') { + getScripts(); } - getScripts(); + open.value = true; } catch (error) {} }; @@ -372,10 +406,10 @@ const acceptParams = async (props: OperateRrops) => { if (props.mode === 'create') { Object.assign(runtime, initData(props.type)); searchApp(null); + open.value = true; } else { getRuntime(props.id); } - open.value = true; }; defineExpose({