更新扩展连接协议字段并且新增邀请码展示

This commit is contained in:
2025-10-22 21:49:57 +08:00
parent 0d91ce138d
commit 17ea51b583
8 changed files with 252 additions and 67 deletions
+29 -6
View File
@@ -41,19 +41,24 @@ class KROutboundItem {
tag = nodeListItem.name; // 设置标签
serverAddr = nodeListItem.serverAddr; // 设置服务器地址
// 将 config 字符串转换为 Map<String, dynamic>
city = nodeListItem.city; // 设置城市
country = nodeListItem.country; // 设置国家
// 安全解析 config 字段
// 新API格式:config为空,直接使用节点字段构建配置
// 旧API格式:config包含JSON配置
if (nodeListItem.config.isEmpty) {
// 🔧 优先使用直接字段构建配置(新API格式)
// 判断条件:如果有 port 和 serverAddr,说明是新格式
if (nodeListItem.port > 0 && nodeListItem.serverAddr.isNotEmpty) {
print('️ 节点 ${nodeListItem.name} 使用直接字段构建配置');
_buildConfigFromFields(nodeListItem);
return;
}
// 兜底:尝试解析 config 字段(旧API格式)
if (nodeListItem.config.isEmpty) {
print('❌ 节点 ${nodeListItem.name} 缺少配置信息(无port或config)');
config = {};
return;
}
late Map<String, dynamic> json;
try {
json = jsonDecode(nodeListItem.config) as Map<String, dynamic>;
@@ -228,17 +233,31 @@ class KROutboundItem {
/// 直接从节点字段构建配置(新API格式)
void _buildConfigFromFields(KrNodeListItem nodeListItem) {
print('🔧 开始构建节点配置 - 协议: ${nodeListItem.protocol}, 名称: ${nodeListItem.name}');
print('📋 节点详细信息:');
print(' - serverAddr: ${nodeListItem.serverAddr}');
print(' - port: ${nodeListItem.port}');
print(' - uuid: ${nodeListItem.uuid}');
print(' - method: ${nodeListItem.method}');
switch (nodeListItem.protocol) {
case "shadowsocks":
// 优先使用 protocols 解析出来的 cipher,其次是 method 字段,最后才是默认值
String finalMethod = nodeListItem.method.isNotEmpty
? nodeListItem.method
: "2022-blake3-aes-256-gcm";
config = {
"type": "shadowsocks",
"tag": nodeListItem.name,
"server": nodeListItem.serverAddr,
"server_port": nodeListItem.port,
"method": "chacha20-ietf-poly1305", // 默认加密方法
"method": finalMethod,
"password": nodeListItem.uuid
};
print('✅ Shadowsocks 节点配置构建成功: ${nodeListItem.name}');
print('📄 使用加密方法: $finalMethod');
print('📄 完整配置: $config');
break;
case "vless":
config = {
@@ -258,6 +277,7 @@ class KROutboundItem {
}
};
print('✅ VLESS 节点配置构建成功: ${nodeListItem.name}');
print('📄 完整配置: $config');
break;
case "vmess":
config = {
@@ -276,6 +296,7 @@ class KROutboundItem {
}
};
print('✅ VMess 节点配置构建成功: ${nodeListItem.name}');
print('📄 完整配置: $config');
break;
case "trojan":
config = {
@@ -292,6 +313,7 @@ class KROutboundItem {
}
};
print('✅ Trojan 节点配置构建成功: ${nodeListItem.name}');
print('📄 完整配置: $config');
break;
case "hysteria2":
config = {
@@ -310,6 +332,7 @@ class KROutboundItem {
}
};
print('✅ Hysteria2 节点配置构建成功: ${nodeListItem.name}');
print('📄 完整配置: $config');
break;
default:
print('⚠️ 不支持的协议类型: ${nodeListItem.protocol}');