From 71ba1534f2d518c7f5984f46548fcb9f6128fe82 Mon Sep 17 00:00:00 2001 From: whyour Date: Tue, 2 Jul 2024 00:44:48 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=87=AA=E5=AE=9A=E5=86=99?= =?UTF-8?q?=E5=85=A5=20js=20=E5=92=8C=20py=20=E7=B1=BB=E5=9E=8B=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- back/config/index.ts | 6 ++++++ back/services/env.ts | 11 +++++++++++ shell/share.sh | 4 +++- 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/back/config/index.ts b/back/config/index.ts index 1c426811..b9d33b85 100644 --- a/back/config/index.ts +++ b/back/config/index.ts @@ -38,6 +38,8 @@ const sshdPath = path.join(dataPath, 'ssh.d/'); const systemLogPath = path.join(dataPath, 'syslog/'); const envFile = path.join(configPath, 'env.sh'); +const jsEnvFile = path.join(configPath, 'env.js'); +const pyEnvFile = path.join(configPath, 'env.py'); const confFile = path.join(configPath, 'config.sh'); const crontabFile = path.join(configPath, 'crontab.list'); const authConfigFile = path.join(configPath, 'auth.json'); @@ -87,6 +89,8 @@ export default { sampleFile, confFile, envFile, + jsEnvFile, + pyEnvFile, dbPath, uploadPath, configPath, @@ -99,6 +103,8 @@ export default { 'crontab.list', 'dependence-proxy.sh', 'env.sh', + 'env.js', + 'env.py', 'token.json', ], writePathList: [configPath, scriptPath], diff --git a/back/services/env.ts b/back/services/env.ts index 836b7211..27a0b76d 100644 --- a/back/services/env.ts +++ b/back/services/env.ts @@ -196,6 +196,8 @@ export default class EnvService { }); const groups = groupBy(envs, 'name'); let env_string = ''; + let js_env_string = ''; + let py_env_string = 'import os\n'; for (const key in groups) { if (Object.prototype.hasOwnProperty.call(groups, key)) { const group = groups[key]; @@ -208,9 +210,18 @@ export default class EnvService { .replace(/'/g, "'\\''") .trim(); env_string += `export ${key}='${value}'\n`; + const _env_value = `'${group + .map((x) => x.value) + .join('&') + .replace(/\\/g, '\\\\') + .replace(/'/g, "\\'")}'`; + js_env_string += `process.env.${key}=${_env_value};\n`; + py_env_string += `os.environ['${key}']=${_env_value}\n`; } } } await fs.writeFile(config.envFile, env_string); + await fs.writeFile(config.jsEnvFile, js_env_string); + await fs.writeFile(config.pyEnvFile, py_env_string); } } diff --git a/shell/share.sh b/shell/share.sh index 44af0f73..e019c726 100755 --- a/shell/share.sh +++ b/shell/share.sh @@ -74,7 +74,9 @@ init_env() { import_config() { [[ -f $file_config_user ]] && . $file_config_user - [[ -f $file_env ]] && . $file_env + if [[ $LOAD_ENV != 'false' ]] && [[ -f $file_env ]]; then + . $file_env + fi ql_base_url=${QlBaseUrl:-"/"} ql_port=${QlPort:-"5700"}