mirror of
https://github.com/Sagit-chu/flvx.git
synced 2026-10-07 10:16:38 +08:00
fix: bound and configure tunnel quality probes (#533)
Closes #528 and #532.
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
export const TUNNEL_QUALITY_INTERVAL_CONFIG_KEY =
|
||||
"monitor_tunnel_quality_interval_sec";
|
||||
export const DEFAULT_TUNNEL_QUALITY_INTERVAL_SEC = 1;
|
||||
export const MIN_TUNNEL_QUALITY_INTERVAL_SEC = 1;
|
||||
export const MAX_TUNNEL_QUALITY_INTERVAL_SEC = 3600;
|
||||
|
||||
export const parseTunnelQualityIntervalSeconds = (value: unknown): number => {
|
||||
const seconds = Number(value);
|
||||
|
||||
return Number.isInteger(seconds) &&
|
||||
seconds >= MIN_TUNNEL_QUALITY_INTERVAL_SEC &&
|
||||
seconds <= MAX_TUNNEL_QUALITY_INTERVAL_SEC
|
||||
? seconds
|
||||
: DEFAULT_TUNNEL_QUALITY_INTERVAL_SEC;
|
||||
};
|
||||
|
||||
export const validateTunnelQualityInterval = (value: string): string | null => {
|
||||
const normalized = value.trim();
|
||||
|
||||
if (!normalized) {
|
||||
return "请输入探测间隔";
|
||||
}
|
||||
const seconds = Number(normalized);
|
||||
|
||||
if (!Number.isInteger(seconds)) {
|
||||
return "探测间隔必须是整数";
|
||||
}
|
||||
if (
|
||||
seconds < MIN_TUNNEL_QUALITY_INTERVAL_SEC ||
|
||||
seconds > MAX_TUNNEL_QUALITY_INTERVAL_SEC
|
||||
) {
|
||||
return `探测间隔必须在 ${MIN_TUNNEL_QUALITY_INTERVAL_SEC} 到 ${MAX_TUNNEL_QUALITY_INTERVAL_SEC} 秒之间`;
|
||||
}
|
||||
|
||||
return null;
|
||||
};
|
||||
|
||||
export const tunnelQualityIntervalLabel = (seconds: number): string =>
|
||||
seconds === 1 ? "每秒" : `每 ${seconds} 秒`;
|
||||
Reference in New Issue
Block a user