更新扩展连接协议字段并且新增邀请码展示
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:convert';
|
||||
import 'package:kaer_with_panels/app/utils/kr_log_util.dart';
|
||||
|
||||
class KRNodeList {
|
||||
@@ -54,7 +55,9 @@ class KrNodeListItem {
|
||||
final String relayMode;
|
||||
final String relayNode;
|
||||
final String serverAddr;
|
||||
final int port; // 新增:端口字段
|
||||
final int port; // 端口字段
|
||||
final String method; // 加密方法(用于Shadowsocks等)
|
||||
final String protocols; // 协议配置JSON字符串(新API格式)
|
||||
final int speedLimit;
|
||||
final List<String> tags;
|
||||
final int traffic;
|
||||
@@ -81,6 +84,8 @@ class KrNodeListItem {
|
||||
this.relayNode = '',
|
||||
required this.serverAddr,
|
||||
this.port = 0, // 默认值
|
||||
this.method = '', // 默认空字符串
|
||||
this.protocols = '', // 默认空字符串
|
||||
required this.speedLimit,
|
||||
required this.tags,
|
||||
required this.traffic,
|
||||
@@ -102,10 +107,33 @@ class KrNodeListItem {
|
||||
factory KrNodeListItem.fromJson(Map<String, dynamic> json) {
|
||||
try {
|
||||
// 支持新旧两种API格式
|
||||
// 新格式: address, port
|
||||
// 最新格式: protocols 字段包含协议配置数组
|
||||
// 新格式: address, port, method(直接字段)
|
||||
// 旧格式: server_addr, config 中包含 port
|
||||
final serverAddr = json['address']?.toString() ?? json['server_addr']?.toString() ?? '';
|
||||
final port = _parseIntSafely(json['port']);
|
||||
int port = _parseIntSafely(json['port']);
|
||||
String method = json['method']?.toString() ?? ''; // 加密方法(Shadowsocks等)
|
||||
final protocols = json['protocols']?.toString() ?? ''; // 协议配置JSON
|
||||
|
||||
// 🔧 如果有 protocols 字段,从中解析 port 和 cipher
|
||||
if (protocols.isNotEmpty) {
|
||||
try {
|
||||
final protocolsList = jsonDecode(protocols) as List;
|
||||
if (protocolsList.isNotEmpty) {
|
||||
final firstProtocol = protocolsList[0] as Map<String, dynamic>;
|
||||
// 优先使用 protocols 中的配置
|
||||
if (firstProtocol['port'] != null) {
|
||||
port = _parseIntSafely(firstProtocol['port']);
|
||||
}
|
||||
if (firstProtocol['cipher'] != null && firstProtocol['cipher'].toString().isNotEmpty) {
|
||||
method = firstProtocol['cipher'].toString();
|
||||
}
|
||||
KRLogUtil.kr_i('从 protocols 解析: port=$port, cipher=$method', tag: 'NodeList');
|
||||
}
|
||||
} catch (e) {
|
||||
KRLogUtil.kr_w('解析 protocols 字段失败: $e', tag: 'NodeList');
|
||||
}
|
||||
}
|
||||
|
||||
return KrNodeListItem(
|
||||
id: _parseIntSafely(json['id']),
|
||||
@@ -116,6 +144,8 @@ class KrNodeListItem {
|
||||
relayNode: json['relay_node']?.toString() ?? '',
|
||||
serverAddr: serverAddr,
|
||||
port: port,
|
||||
method: method,
|
||||
protocols: protocols,
|
||||
speedLimit: _parseIntSafely(json['speed_limit']),
|
||||
tags: _parseStringList(json['tags']),
|
||||
traffic: _parseIntSafely(json['traffic']),
|
||||
@@ -142,6 +172,8 @@ class KrNodeListItem {
|
||||
protocol: '',
|
||||
serverAddr: '',
|
||||
port: 0,
|
||||
method: '',
|
||||
protocols: '',
|
||||
speedLimit: 0,
|
||||
tags: [],
|
||||
traffic: 0,
|
||||
|
||||
@@ -6,7 +6,11 @@ class KRUserInfo {
|
||||
final String avatar;
|
||||
final String areaCode;
|
||||
final String telephone;
|
||||
final int balance;
|
||||
final int balance;
|
||||
final int commission;
|
||||
final int referralPercentage;
|
||||
final bool onlyFirstPurchase;
|
||||
final int giftAmount;
|
||||
|
||||
KRUserInfo({
|
||||
required this.id,
|
||||
@@ -16,7 +20,11 @@ class KRUserInfo {
|
||||
this.avatar = '',
|
||||
this.areaCode = '',
|
||||
this.telephone = '',
|
||||
this.balance = 0
|
||||
this.balance = 0,
|
||||
this.commission = 0,
|
||||
this.referralPercentage = 0,
|
||||
this.onlyFirstPurchase = false,
|
||||
this.giftAmount = 0,
|
||||
});
|
||||
|
||||
factory KRUserInfo.fromJson(Map<String, dynamic> json) {
|
||||
@@ -28,7 +36,11 @@ class KRUserInfo {
|
||||
avatar: json['avatar'] ?? '',
|
||||
areaCode: json['area_code'] ?? '',
|
||||
telephone: json['telephone'] ?? '',
|
||||
balance: json['balance'] ?? 0,
|
||||
balance: json['balance'] ?? 0,
|
||||
commission: json['commission'] ?? 0,
|
||||
referralPercentage: json['referral_percentage'] ?? 0,
|
||||
onlyFirstPurchase: json['only_first_purchase'] ?? false,
|
||||
giftAmount: json['gift_amount'] ?? 0,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user