68 lines
2.1 KiB
JavaScript
68 lines
2.1 KiB
JavaScript
import {
|
|
normalizeAppPromotions,
|
|
normalizeComplianceDocument,
|
|
normalizeComplianceDocumentKey,
|
|
normalizeHelpArticles,
|
|
normalizePromotionPlacement,
|
|
normalizeSiteArticles
|
|
} from './site-content-contract.js'
|
|
import { requestStrict } from './request-client.js'
|
|
|
|
export const siteContentApi = {
|
|
async getSiteArticles(requestOptions = {}) {
|
|
const limit = requestOptions.limit ?? 20
|
|
if (!Number.isSafeInteger(limit) || limit < 1 || limit > 100) {
|
|
throw new TypeError('官网文章数量上限无效')
|
|
}
|
|
const articleType = typeof requestOptions.articleType === 'string'
|
|
? requestOptions.articleType.trim()
|
|
: ''
|
|
const articles = await requestStrict({
|
|
url: '/genealogy/app/site/articles',
|
|
method: 'GET',
|
|
data: {
|
|
limit,
|
|
...(articleType ? { articleType } : {})
|
|
}
|
|
}, {
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return normalizeSiteArticles(articles)
|
|
},
|
|
|
|
async getHelpArticles(requestOptions = {}) {
|
|
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')
|
|
const promotions = await requestStrict({
|
|
url: '/genealogy/app/promotions',
|
|
method: 'GET',
|
|
data: { platform: 'app', placement }
|
|
}, {
|
|
authenticated: false,
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return normalizeAppPromotions(promotions, placement)
|
|
},
|
|
|
|
async getComplianceDocument(documentKey, requestOptions = {}) {
|
|
const normalizedKey = normalizeComplianceDocumentKey(documentKey)
|
|
const complianceDocument = await requestStrict({
|
|
url: `/genealogy/app/compliance/documents/${normalizedKey}`,
|
|
method: 'GET'
|
|
}, {
|
|
authenticated: false,
|
|
requestController: requestOptions.requestController ?? null
|
|
})
|
|
return normalizeComplianceDocument(complianceDocument, normalizedKey)
|
|
}
|
|
}
|