liufumingren 018bbd379d feat(warehouse): 前置仓前端配置与按域名公开拉取接口
- 新增模型 wms_warehouse_front_config 与迁移:建表、
  追加 favicon_url、追加 cert_pem(可回滚)
- systems/setting/warehouse.js 实现 getFrontConfig / saveFrontConfig / saveFrontCert、
  域名唯一性校验、按域名缓存读取(含未登记域名的短 TTL 空缓存防穿透)与缓存清理
- systemMethods/setting/warehouse.js 开放对应 system method
- 新增公共免登录接口 frontConfig.getByDomain:按域名返回公开字段
  (domain/title/logo_url/login_bg_url/favicon_url/theme),
  不返回 cert_path/key_path/sync_status 等内部字段;未登记域名返回 404
2026-09-13 15:31:02 +08:00

47 lines
1.8 KiB
JavaScript
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.

'use strict';
const MainService = require('../main');
class FrontConfigMethodsService extends MainService {
constructor(ctx) {
super(ctx);
// 公共按域名拉取前端配置:免登录、免权限、免鉴权(保留系统日志,与 workbench 公共接口口径一致)
const _noNeedLogin = 'getByDomain';
const _noNeedRight = 'getByDomain';
const _noNeedLog = '';
const _noNeedAuth = 'getByDomain';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 按域名拉取仓库前端公开配置(公共无鉴权接口)。
*
* 安全红线:响应仅含公开字段(domain/title/logo_url/login_bg_url/favicon_url/theme),
* 不含 cert_path、key_path、sync_status、sync_attempts、last_sync_error 等内部字段。
*
* @param {Object} [data={}] 请求参数。
* @param {string} data.domain 待查询域名(必填,非空)。
* @return {Promise<Object>} 统一响应结构;命中返回公开字段配置(code=200),
* 未登记域名返回 code=404「域名未配置」。
*/
async getByDomain(data = {}) {
const { domain } = data || {};
const targetService = this.service && this.service.systems && this.service.systems.setting && this.service.systems.setting.warehouse;
if (!targetService || typeof targetService.getFrontConfigByDomain !== 'function') {
return this.fail('获取前端配置失败', { code: 500 });
}
try {
const result = await targetService.getFrontConfigByDomain(domain);
return this.success('获取成功', { ...result, code: 200 });
} catch (error) {
return this.fail(error.message || '获取前端配置失败', {
code: Number(error.code) || 500,
});
}
}
}
module.exports = FrontConfigMethodsService;