修复 kuaishou-lewan 多账号健康检查与平台配置展示
恢复 health 任务对全部账号的合并监控,补齐 React 后台多账号 UI 与账号选择,并将用户可见文案统一为 kuaishou-lewan。
This commit is contained in:
@@ -170,21 +170,63 @@ function mapScheduledJobCloudtentaclesAccounts(
|
||||
cloudtentaclesAccountMap: Map<string, JsonObject>,
|
||||
) {
|
||||
const accounts = Array.isArray(rawAccounts) ? rawAccounts : []
|
||||
return accounts.map((item) => {
|
||||
const source = isPlainObject(item) ? item : {}
|
||||
const sourceKey = String(source.sourceKey || source.key || '').trim()
|
||||
const option = cloudtentaclesAccountMap.get(sourceKey) || {}
|
||||
const configuredMap = new Map(
|
||||
accounts
|
||||
.map((item) => {
|
||||
const source = isPlainObject(item) ? item : {}
|
||||
const sourceKey = String(source.sourceKey || source.key || '').trim()
|
||||
if (!sourceKey) {
|
||||
return null
|
||||
}
|
||||
|
||||
const option = cloudtentaclesAccountMap.get(sourceKey) || {}
|
||||
return [
|
||||
sourceKey,
|
||||
{
|
||||
sourceKey,
|
||||
label: String(source.label || option.label || sourceKey).trim(),
|
||||
enabled: source.enabled !== false,
|
||||
assetThreshold: normalizeNonNegativeNumber(
|
||||
source.assetThreshold ?? source.threshold,
|
||||
defaultAssetThreshold,
|
||||
),
|
||||
},
|
||||
] as const
|
||||
})
|
||||
.filter(Boolean) as Array<readonly [string, {
|
||||
sourceKey: string
|
||||
label: string
|
||||
enabled: boolean
|
||||
assetThreshold: number
|
||||
}]>,
|
||||
)
|
||||
|
||||
// 读配置时合并全部 kuaishou-lewan 账号,避免前端/任务只看到历史 default。
|
||||
const merged = Array.from(cloudtentaclesAccountMap.values()).map((option) => {
|
||||
const sourceKey = String(option.sourceKey || '').trim()
|
||||
const configured = configuredMap.get(sourceKey)
|
||||
return {
|
||||
sourceKey,
|
||||
label: String(source.label || option.label || sourceKey).trim(),
|
||||
enabled: source.enabled !== false,
|
||||
label: String(configured?.label || option.label || sourceKey).trim(),
|
||||
enabled: configured
|
||||
? configured.enabled !== false
|
||||
: option.enabled !== false,
|
||||
assetThreshold: normalizeNonNegativeNumber(
|
||||
source.assetThreshold ?? source.threshold,
|
||||
configured?.assetThreshold,
|
||||
defaultAssetThreshold,
|
||||
),
|
||||
}
|
||||
}).filter((item) => item.sourceKey)
|
||||
|
||||
const mergedKeys = new Set(merged.map((item) => item.sourceKey))
|
||||
for (const [sourceKey, configured] of configuredMap.entries()) {
|
||||
if (mergedKeys.has(sourceKey)) {
|
||||
continue
|
||||
}
|
||||
merged.push(configured)
|
||||
}
|
||||
|
||||
return merged
|
||||
}
|
||||
|
||||
function normalizeNonNegativeNumber(value: unknown, fallback: number) {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user