- 新增 PDF 文档支持,包括格式校验和完整性检查 - 扩展 Word、TXT 和 ZIP 格式附件处理能力 - 添加 Excel 附件可选择仅作为业务文件不解析行数据 - 实现业务助手表格布局配置新增库存和预算字段 - 集成通知、反馈通知等新的业务助手动作类型 - 完善部门管理包含父级部门和排序字段支持 - 增强业务规则校验涵盖更多系统管理场景 - 优化附件上传限制提示信息更准确 - 添加生成文件下载的安全性校验机制 - 扩展测试覆盖确保各业务动作规则正确性
24 lines
1.5 KiB
JavaScript
24 lines
1.5 KiB
JavaScript
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
function internal(value, dev) {
|
|
const url = new URL(value);
|
|
const p = url.hostname.split('.').map(Number);
|
|
const ipv4 = p.length === 4 && p.every(v => Number.isInteger(v) && v >= 0 && v <= 255);
|
|
if (!['http:', 'https:'].includes(url.protocol) || url.username || url.password || url.search || url.hash
|
|
|| !(ipv4 && (p[0] === 10 || p[0] === 192 && p[1] === 168 || p[0] === 172 && p[1] >= 16 && p[1] <= 31)
|
|
|| dev && ['localhost', '127.0.0.1'].includes(url.hostname))) throw Error('App 地址必须是内网 IPv4 地址;开发环境也可用 localhost。');
|
|
return url.toString().replace(/\/$/, '');
|
|
}
|
|
function environment(env = process.env) {
|
|
const variant = env.APP_ENV || 'dev';
|
|
if (!['dev', 'prod'].includes(variant)) throw Error('APP_ENV 只能是 dev 或 prod');
|
|
const dev = variant === 'dev';
|
|
const apiUrl = internal(env.APP_API_URL || (dev ? 'http://127.0.0.1:8080' : ''), dev);
|
|
const updateOrigin = internal(env.APP_UPDATE_ORIGIN || (dev ? 'http://127.0.0.1:8090' : ''), dev);
|
|
if (new URL(updateOrigin).pathname !== '/') throw Error('APP_UPDATE_ORIGIN 只能包含协议、内网地址和端口。');
|
|
const certificate = path.resolve(__dirname, '../certs', `${variant}.pem`);
|
|
if (!dev && !fs.existsSync(certificate)) throw Error('正式构建必须先配置 certs/prod.pem 更新签名证书。');
|
|
return { variant, apiUrl, updateOrigin, certificate, updatesEnabled: fs.existsSync(certificate) };
|
|
}
|
|
module.exports = { environment, internal };
|