修复 kuaishou-lewan 多账号健康检查与平台配置展示

恢复 health 任务对全部账号的合并监控,补齐 React 后台多账号 UI 与账号选择,并将用户可见文案统一为 kuaishou-lewan。
This commit is contained in:
yml2213
2026-07-10 21:43:32 +08:00
parent 01f46e4fc7
commit 3196e1ccdc
7 changed files with 558 additions and 112 deletions
@@ -191,23 +191,64 @@ function resolveCloudtentaclesHealthAccounts(job: JsonObject) {
const rawAccounts = Array.isArray(config.accounts) ? config.accounts : []
const defaultThreshold = normalizeNonNegativeInteger(config.assetThreshold, 500)
const sourceConfig = listCloudtentaclesSources()
const sources = Array.isArray(sourceConfig.sources) ? sourceConfig.sources : []
const sourceMap = new Map(
(Array.isArray(sourceConfig.sources) ? sourceConfig.sources : [])
.map((source) => [String(source.key || '').trim(), source]),
sources
.map((source) => [String(source.key || '').trim(), source] as const)
.filter(([sourceKey]) => Boolean(sourceKey)),
)
const normalizedAccounts = rawAccounts
.map((item) => normalizeCloudtentaclesHealthAccount(item, defaultThreshold, sourceMap))
const configuredMap = new Map(
rawAccounts
.map((item) => normalizeCloudtentaclesHealthAccount(item, defaultThreshold, sourceMap))
.filter(Boolean)
.map((item) => [String(item!.sourceKey || '').trim(), item!] as const)
.filter(([sourceKey]) => Boolean(sourceKey)),
)
// 以平台配置中的全部账号为准,合并任务里已保存的阈值/开关;新增账号自动纳入监控。
const mergedAccounts = sources
.map((source) => {
const sourceKey = String(source.key || '').trim()
if (!sourceKey) {
return null
}
const configured = configuredMap.get(sourceKey)
return {
sourceKey,
label: String(
configured?.label || source.label || source.username || sourceKey,
).trim() || sourceKey,
enabled: configured
? configured.enabled !== false
: source.enabled !== false,
assetThreshold: normalizeNonNegativeInteger(
configured?.assetThreshold,
defaultThreshold,
),
}
})
.filter(Boolean) as JsonObject[]
if (normalizedAccounts.length > 0) {
return dedupeAccounts(normalizedAccounts)
// 保留已配置但源账号已删除的项,便于报 source_missing。
for (const [sourceKey, configured] of configuredMap.entries()) {
if (sourceMap.has(sourceKey)) {
continue
}
mergedAccounts.push(configured)
}
if (mergedAccounts.length > 0) {
return dedupeAccounts(mergedAccounts)
}
// 兼容旧配置:没有任何平台账号时,仍检查历史 default。
const fallback = configuredMap.get('default')
return [{
sourceKey: 'default',
label: sourceMap.get('default')?.label || '默认账号',
enabled: true,
assetThreshold: defaultThreshold,
label: String(fallback?.label || '默认账号').trim() || '默认账号',
enabled: fallback ? fallback.enabled !== false : true,
assetThreshold: normalizeNonNegativeInteger(fallback?.assetThreshold, defaultThreshold),
}]
}
@@ -249,7 +290,7 @@ function dedupeAccounts(accounts: JsonObject[]) {
function buildCloudtentaclesHealthSummary(results: CloudtentaclesHealthAccountResult[]) {
if (results.length === 0) {
return '未配置 cloudtentacles 监控账号'
return '未配置 kuaishou-lewan 监控账号'
}
const checkedResults = results.filter((item) => !item.skipped)