feat(channel-monitor-v2): 补齐管理端配置、隐藏吞吐开关与测试

管理端 V2 配置面板与系统设置中的模式/隐藏 RPM·TPM 开关,纳入关键
vitest 与 Makefile 前端关键路径,覆盖门控与展示行为。
This commit is contained in:
IanShaw027
2026-08-07 11:05:32 +08:00
parent d8c5024cee
commit d2d91ff9a8
10 changed files with 244 additions and 27 deletions
+35 -1
View File
@@ -68,9 +68,9 @@
* `makeSidebarFlag(flag)` returns a `() => boolean | undefined` compatible with
* `AppSidebar.NavItem.featureFlag`, where `false` hides the menu entry.
*/
import { useAppStore } from '@/stores/app'
import type { PublicSettings } from '@/types'
import { DEFAULT_INTERVAL_SECONDS } from '@/constants/channelMonitor'
export type FeatureFlagMode = 'opt-in' | 'opt-out'
@@ -152,3 +152,37 @@ export function isFeatureFlagEnabled(flag: FeatureFlagDefinition): boolean {
export function makeSidebarFlag(flag: FeatureFlagDefinition): () => boolean {
return () => isFeatureFlagEnabled(flag)
}
/** True when channel monitor feature flag is enabled. */
export function isChannelMonitorRouteEnabled(): boolean {
return isFeatureFlagEnabled(FeatureFlags.channelMonitor)
}
export type ChannelMonitorMode = 'v1' | 'v2'
/** Exclusive channel-monitor implementation. Invalid/missing → v2. */
export function getChannelMonitorMode(): ChannelMonitorMode {
const appStore = useAppStore()
const mode = appStore.cachedPublicSettings?.channel_monitor_mode
return mode === 'v1' ? 'v1' : 'v2'
}
export function isChannelMonitorV1Mode(): boolean {
return isChannelMonitorRouteEnabled() && getChannelMonitorMode() === 'v1'
}
export function isChannelMonitorV2Mode(): boolean {
return isChannelMonitorRouteEnabled() && getChannelMonitorMode() === 'v2'
}
export function getChannelMonitorRefreshIntervalSeconds(): number {
const appStore = useAppStore()
const configured = appStore.cachedPublicSettings?.channel_monitor_default_interval_seconds
return configured && configured > 0 ? configured : DEFAULT_INTERVAL_SECONDS
}
/** Hide RPM/TPM on user-facing monitor (scale privacy). Admin always shows full metrics. */
export function isChannelMonitorThroughputHidden(): boolean {
const appStore = useAppStore()
return Boolean(appStore.cachedPublicSettings?.channel_monitor_hide_throughput)
}