39 lines
1.6 KiB
JavaScript
39 lines
1.6 KiB
JavaScript
// 多模态网关凭据只允许在打包时注入,不写进仓库或路由分组配置。
|
|
const fs = require("fs");
|
|
const path = require("path");
|
|
|
|
const DEFAULT_BASE_URL = "https://api.tokendun.com";
|
|
const DEFAULT_MODEL = "MiniMax-M3";
|
|
|
|
function readJson(file) {
|
|
try {
|
|
return JSON.parse(fs.readFileSync(file, "utf-8"));
|
|
} catch {
|
|
return null;
|
|
}
|
|
}
|
|
|
|
function configFiles() {
|
|
const files = [];
|
|
if (process.env.TD_MULTIMODAL_GATEWAY_CONFIG) files.push(process.env.TD_MULTIMODAL_GATEWAY_CONFIG);
|
|
// 热更新目录不随完整安装包携带 resources;将凭据放在 userData 后可被热更新代码稳定读取。
|
|
try {
|
|
const { app } = require("electron");
|
|
if (app && app.getPath) files.push(path.join(app.getPath("userData"), "multimodal-gateway.json"));
|
|
} catch {}
|
|
if (process.resourcesPath) files.push(path.join(process.resourcesPath, "multimodal-gateway.json"));
|
|
files.push(path.join(__dirname, "..", "..", "resources", "multimodal-gateway.json"));
|
|
return Array.from(new Set(files));
|
|
}
|
|
|
|
function gatewayConfig() {
|
|
const fileConfig = configFiles().map(readJson).find(Boolean) || {};
|
|
const baseUrl = String(process.env.TD_MULTIMODAL_GATEWAY_URL || fileConfig.baseUrl || DEFAULT_BASE_URL).trim();
|
|
const key = String(process.env.TD_MULTIMODAL_GATEWAY_KEY || fileConfig.key || "").trim();
|
|
const model = String(process.env.TD_MULTIMODAL_MODEL || fileConfig.model || DEFAULT_MODEL).trim();
|
|
const sttModel = String(process.env.TD_MULTIMODAL_STT_MODEL || fileConfig.sttModel || "").trim();
|
|
return { baseUrl, key, model, sttModel };
|
|
}
|
|
|
|
module.exports = { gatewayConfig };
|