mirror of
				https://github.com/whyour/qinglong.git
				synced 2025-10-31 17:06:07 +08:00 
			
		
		
		
	增加自定写入 js 和 py 类型环境变量
This commit is contained in:
		
							parent
							
								
									791cf657b5
								
							
						
					
					
						commit
						71ba1534f2
					
				|  | @ -38,6 +38,8 @@ const sshdPath = path.join(dataPath, 'ssh.d/'); | ||||||
| const systemLogPath = path.join(dataPath, 'syslog/'); | const systemLogPath = path.join(dataPath, 'syslog/'); | ||||||
| 
 | 
 | ||||||
| const envFile = path.join(configPath, 'env.sh'); | 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 confFile = path.join(configPath, 'config.sh'); | ||||||
| const crontabFile = path.join(configPath, 'crontab.list'); | const crontabFile = path.join(configPath, 'crontab.list'); | ||||||
| const authConfigFile = path.join(configPath, 'auth.json'); | const authConfigFile = path.join(configPath, 'auth.json'); | ||||||
|  | @ -87,6 +89,8 @@ export default { | ||||||
|   sampleFile, |   sampleFile, | ||||||
|   confFile, |   confFile, | ||||||
|   envFile, |   envFile, | ||||||
|  |   jsEnvFile, | ||||||
|  |   pyEnvFile, | ||||||
|   dbPath, |   dbPath, | ||||||
|   uploadPath, |   uploadPath, | ||||||
|   configPath, |   configPath, | ||||||
|  | @ -99,6 +103,8 @@ export default { | ||||||
|     'crontab.list', |     'crontab.list', | ||||||
|     'dependence-proxy.sh', |     'dependence-proxy.sh', | ||||||
|     'env.sh', |     'env.sh', | ||||||
|  |     'env.js', | ||||||
|  |     'env.py', | ||||||
|     'token.json', |     'token.json', | ||||||
|   ], |   ], | ||||||
|   writePathList: [configPath, scriptPath], |   writePathList: [configPath, scriptPath], | ||||||
|  |  | ||||||
|  | @ -196,6 +196,8 @@ export default class EnvService { | ||||||
|     }); |     }); | ||||||
|     const groups = groupBy(envs, 'name'); |     const groups = groupBy(envs, 'name'); | ||||||
|     let env_string = ''; |     let env_string = ''; | ||||||
|  |     let js_env_string = ''; | ||||||
|  |     let py_env_string = 'import os\n'; | ||||||
|     for (const key in groups) { |     for (const key in groups) { | ||||||
|       if (Object.prototype.hasOwnProperty.call(groups, key)) { |       if (Object.prototype.hasOwnProperty.call(groups, key)) { | ||||||
|         const group = groups[key]; |         const group = groups[key]; | ||||||
|  | @ -208,9 +210,18 @@ export default class EnvService { | ||||||
|             .replace(/'/g, "'\\''") |             .replace(/'/g, "'\\''") | ||||||
|             .trim(); |             .trim(); | ||||||
|           env_string += `export ${key}='${value}'\n`; |           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.envFile, env_string); | ||||||
|  |     await fs.writeFile(config.jsEnvFile, js_env_string); | ||||||
|  |     await fs.writeFile(config.pyEnvFile, py_env_string); | ||||||
|   } |   } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -74,7 +74,9 @@ init_env() { | ||||||
| 
 | 
 | ||||||
| import_config() { | import_config() { | ||||||
|   [[ -f $file_config_user ]] && . $file_config_user |   [[ -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_base_url=${QlBaseUrl:-"/"} | ||||||
|   ql_port=${QlPort:-"5700"} |   ql_port=${QlPort:-"5700"} | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 whyour
						whyour