import { hasRemoteConfig } from '@/utils/runtime-config.js' import { normalizeAppPromotions, normalizeComplianceDocument, normalizeComplianceDocumentKey, normalizeHelpArticles, normalizePromotionPlacement } from './site-content-contract.js' import { createRequestError, requestStrict } from './request-client.js' const requireRemoteSiteContent = (label) => { if (hasRemoteConfig()) return throw createRequestError(`${label}读取需要真实服务,当前本地预览不会伪造结果`, 'REMOTE_READ_REQUIRED') } export const siteContentApi = { async getHelpArticles(requestOptions = {}) { requireRemoteSiteContent('帮助文章') const helpArticles = await requestStrict({ url: '/genealogy/app/help-articles', method: 'GET' }, { requestController: requestOptions.requestController ?? null }) return normalizeHelpArticles(helpArticles) }, async getPromotions(requestOptions = {}) { const placement = normalizePromotionPlacement(requestOptions.placement ?? 'home_banner') requireRemoteSiteContent('应用推广') const promotions = await requestStrict({ url: '/genealogy/app/promotions', method: 'GET', data: { platform: 'app', placement } }, { requestController: requestOptions.requestController ?? null }) return normalizeAppPromotions(promotions, placement) }, async getComplianceDocument(documentKey, requestOptions = {}) { requireRemoteSiteContent('协议正文') const normalizedKey = normalizeComplianceDocumentKey(documentKey) const complianceDocument = await requestStrict({ url: `/genealogy/app/compliance/documents/${normalizedKey}`, method: 'GET' }, { requestController: requestOptions.requestController ?? null }) return normalizeComplianceDocument(complianceDocument, normalizedKey) } }