'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} 统一响应结构;命中返回公开字段配置(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;