Files
Artveris/apps/api/src/config/runtime-config.ts
T
Nixevol f712b16c1f fix: 修复后端竞态/安全/数据处理问题并移除冗余 outImage 列
首次激活改条件更新消除并发竞态;备份恢复补模型全集与版本校验防清库;
审核列表分页总数、操作日志未捕获 Promise、出库导入重复码、加密密钥可编辑、
溯源码盐以 env 为准、证书按 originKey reconcile、env 加载去重等修复;
新增 parseBigId 防非法入参 500、全局安全响应头、去除 SVG 上传、接入 throttler 限流、
入队失败补偿、hashData 稳定序列化、无效码负缓存、看板已激活口径调整;
移除冗余 TraceCode.outImage 列统一 outImages(迁移 drop_trace_code_out_image)。
2026-07-09 13:14:26 +08:00

47 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { existsSync, readFileSync } from 'fs';
import { resolve } from 'path';
// 唯一配置来源:运行目录下的 .env(安装向导写入、升级不覆盖)。
// 可用 ARTVERIS_ENV_FILE 覆盖该文件路径,主要用于本地调试安装向导。
export function envFilePath(): string {
return resolve(process.env.ARTVERIS_ENV_FILE || resolve(process.cwd(), '.env'));
}
function loadEnvFile(path: string): void {
if (!existsSync(path)) return;
const text = readFileSync(path, 'utf8');
for (const rawLine of text.split(/\r?\n/)) {
const line = rawLine.trim();
if (!line || line.startsWith('#')) continue;
const eq = line.indexOf('=');
if (eq <= 0) continue;
const key = line.slice(0, eq).trim();
if (process.env[key] !== undefined) continue;
let value = line.slice(eq + 1).trim();
if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) {
value = value.slice(1, -1);
}
process.env[key] = value;
}
}
// 启动早期把 .env 载入 process.env:优先 ARTVERIS_ENV_FILE / 运行目录 .env,
// 再兼容仓库根 ../../.env(本地开发时 API 的 cwd 为 apps/api)。去重避免重复加载同一文件。
export function preloadRuntimeEnv(): void {
const seen = new Set<string>();
for (const path of [envFilePath(), resolve(process.cwd(), '.env'), resolve(process.cwd(), '../../.env')]) {
if (seen.has(path)) continue;
seen.add(path);
loadEnvFile(path);
}
}
export function isInstallMode(): boolean {
preloadRuntimeEnv();
// 强制安装模式:按目标 .env 是否已生成判定(便于本地用 ARTVERIS_ENV_FILE 调试安装向导)
if (process.env.ARTVERIS_INSTALL_MODE === '1') return !existsSync(envFilePath());
if (process.env.ARTVERIS_INSTALL_MODE === '0') return false;
// 常规:未配置 DATABASE_URL(即未安装)则进入安装向导
return !process.env.DATABASE_URL;
}