Files
Thing/src-tauri/src/mihomo_manager/pseudo.rs
T
2026-08-06 10:33:16 +08:00

72 lines
2.0 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// ===================== 伪节点过滤 =====================
// 单点定义:托盘菜单、自动切换、前端显示过滤(ProxyModule.vue 的 PSEUDO_NODE_KEYWORDS
// 与之对应)统一引用此处,避免多份关键词列表漂移。
/// 订阅节点名中常见的营销/占位关键词(订阅页插入的非真实节点)
const PSEUDO_KEYWORDS: &[&str] = &[
"DIRECT",
"REJECT",
"PASS",
"COMPATIBLE",
"流量",
"套餐",
"到期",
"续费",
"官网",
"网站",
"刷新",
"更新",
"⭐",
"★",
"☆",
"✕",
"✖",
"×",
];
/// 判断节点名是否为伪节点(DIRECT/REJECT 等内置策略或订阅营销占位)
pub fn is_pseudo_node(name: &str) -> bool {
let upper = name.trim().to_uppercase();
if upper == "DIRECT" || upper == "REJECT" || upper == "PASS" || upper == "GLOBAL" {
return true;
}
PSEUDO_KEYWORDS.iter().any(|kw| name.contains(kw))
}
#[cfg(test)]
mod pseudo_node_tests {
use super::*;
#[test]
fn builtin_policies_are_pseudo() {
assert!(is_pseudo_node("DIRECT"));
assert!(is_pseudo_node("REJECT"));
assert!(is_pseudo_node("PASS"));
assert!(is_pseudo_node("GLOBAL"));
}
#[test]
fn case_insensitive_and_trims_whitespace() {
assert!(is_pseudo_node("direct"));
assert!(is_pseudo_node(" Reject "));
}
#[test]
fn marketing_keywords_are_pseudo() {
assert!(is_pseudo_node("香港流量套餐"));
assert!(is_pseudo_node("官网专线"));
assert!(is_pseudo_node("VIP到期续费"));
assert!(is_pseudo_node("每月更新"));
assert!(is_pseudo_node("★香港节点"));
}
#[test]
fn real_nodes_are_not_pseudo() {
assert!(!is_pseudo_node("HK-01"));
assert!(!is_pseudo_node("美国洛杉矶 01"));
assert!(!is_pseudo_node("JP Tokyo 2G"));
assert!(!is_pseudo_node(""));
assert!(!is_pseudo_node("Node-2024"));
}
}