cang-ying/engines/env-loader.js
Guanghu Domestic Migration a2fa7d57d8 chore: import sanitized domestic snapshot for REPO-005
Source snapshot: 23037fa3a2e9b0597162735755e92fc763bf4d94
2026-07-17 15:55:48 +08:00

53 lines
1.4 KiB
JavaScript

const fs = require('fs');
const path = require('path');
const CANONICAL_SECRETS_FILE = '/root/guanghulab-local-secrets/cang-ying.env';
const HOME_SECRETS_FILE = path.join(process.env.HOME || '', 'guanghulab-local-secrets/cang-ying.env');
const SHARED_MAC_SECRETS_FILE = '/Users/bingshuolingdianyuanhe/Documents/guanghulab-local-secrets/video-ai-system.env';
function loadEnvFile(file) {
if (!file || !fs.existsSync(file)) return false;
const content = fs.readFileSync(file, 'utf8');
for (const line of content.split(/\r?\n/)) {
const trimmed = line.trim();
if (!trimmed || trimmed.startsWith('#')) continue;
const eq = trimmed.indexOf('=');
if (eq <= 0) continue;
const key = trimmed.slice(0, eq).trim();
const value = trimmed.slice(eq + 1).trim();
if (!key || !value) continue;
if (!process.env[key]) process.env[key] = value;
}
return true;
}
function loadVideoAiEnv(localEnvPath = path.resolve(__dirname, '../.env')) {
const loaded = [];
const files = [
process.env.VIDEO_AI_SECRETS_FILE,
CANONICAL_SECRETS_FILE,
HOME_SECRETS_FILE,
SHARED_MAC_SECRETS_FILE,
// 仓库内 .env 只保留旧环境迁移兼容;新配置必须使用上面的仓库外路径。
localEnvPath,
];
for (const file of files) {
if (loadEnvFile(file)) loaded.push(file);
}
return loaded;
}
module.exports = {
CANONICAL_SECRETS_FILE,
HOME_SECRETS_FILE,
SHARED_MAC_SECRETS_FILE,
loadVideoAiEnv,
};