优化节点列表拉取可能存在失败的可能
Some checks failed
Build Android APK / 编译 libcore.aar (push) Has been cancelled
Build Multi-Platform / 编译 libcore (iOS/tvOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Android) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Windows) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (macOS) (push) Has been cancelled
Build Multi-Platform / 编译 libcore (Linux) (push) Has been cancelled
Build Windows / 编译 libcore (Windows) (push) Has been cancelled
Build Windows / build (push) Has been cancelled
Build Android APK / 编译 Android APK (release) (push) Has been cancelled
Build Android APK / 创建 GitHub Release (push) Has been cancelled
Build Multi-Platform / 构建 Android APK (push) Has been cancelled
Build Multi-Platform / 构建 Windows (push) Has been cancelled
Build Multi-Platform / 构建 macOS (push) Has been cancelled
Build Multi-Platform / 构建 Linux (push) Has been cancelled
Build Multi-Platform / 构建 iOS (push) Has been cancelled
Build Multi-Platform / 创建 Release (push) Has been cancelled

(cherry picked from commit f59e70ed8b9084d29f792280d94f1c49719842a1)
This commit is contained in:
Rust 2025-11-04 01:07:24 -08:00 committed by speakeloudest
parent 6131a80b2c
commit 4fbdb331d4
2 changed files with 106 additions and 11 deletions

View File

@ -14,6 +14,7 @@ import 'package:kaer_with_panels/app/localization/kr_language_utils.dart';
import 'package:kaer_with_panels/app/utils/kr_common_util.dart';
import 'package:kaer_with_panels/app/services/singbox_imp/kr_sing_box_imp.dart';
import 'package:kaer_with_panels/app/services/kr_site_config_service.dart';
import 'package:kaer_with_panels/singbox/model/singbox_status.dart';
// import 'package:crypto/crypto.dart';
// import 'package:encrypt/encrypt.dart';
@ -79,14 +80,44 @@ class HttpUtil {
createHttpClient: () {
KRLogUtil.kr_i('📱 createHttpClient 回调被调用', tag: 'HttpUtil');
final client = HttpClient();
// 退
client.findProxy = (url) {
final proxyConfig = KRSingBoxImp.instance.kr_buildProxyRule();
KRLogUtil.kr_i(
'🔍 findProxy 被调用, url: $url, proxy: $proxyConfig',
tag: 'HttpUtil',
);
return proxyConfig;
try {
// SingBox
final singBoxStatus = KRSingBoxImp.instance.kr_status;
final isProxyAvailable = singBoxStatus == SingboxStatus.started();
if (!isProxyAvailable) {
// 使
KRLogUtil.kr_i(
'🔄 代理未运行,使用直连模式: $url',
tag: 'HttpUtil',
);
return 'DIRECT';
}
// 使
final proxyConfig = KRSingBoxImp.instance.kr_buildProxyRule();
KRLogUtil.kr_i(
'✅ 使用代理模式, url: $url, proxy: $proxyConfig',
tag: 'HttpUtil',
);
return proxyConfig;
} catch (e) {
// 退
KRLogUtil.kr_w(
'⚠️ 代理配置异常,回退到直连: $e',
tag: 'HttpUtil',
);
return 'DIRECT';
}
};
// 退
client.connectionTimeout = const Duration(seconds: 10);
client.badCertificateCallback = (cert, host, port) => true;
return client;
},
);

View File

@ -95,6 +95,48 @@ class KRSubscribeService {
///
final kr_currentStatus = KRSubscribeServiceStatus.kr_none.obs;
/// 4 -
bool _isRefreshing = false;
/// 5
String _kr_getFriendlyErrorMessage(int errorCode, String originalMsg) {
switch (errorCode) {
case -90001:
return '连接超时,请检查网络连接';
case -90002:
return '发送数据超时,请稍后重试';
case -90003:
return '接收数据超时,网络较慢,请稍后重试';
case -90004:
return '服务器响应异常:$originalMsg';
case -90006:
return '网络连接失败,请检查网络设置';
case -90007:
return '安全证书验证失败';
case -90008:
return '网络连接被中断,请重试';
case 401:
return '登录已过期,请重新登录';
case 403:
return '没有访问权限';
case 404:
return '请求的资源不存在';
case 500:
return '服务器内部错误,请稍后重试';
case 503:
return '服务暂时不可用,请稍后重试';
default:
if (errorCode >= 500 && errorCode < 600) {
return '服务器错误($errorCode),请稍后重试';
} else if (errorCode >= 400 && errorCode < 500) {
return '请求错误($errorCode$originalMsg';
} else if (errorCode < 0) {
return '网络请求失败,请检查网络连接';
}
return originalMsg.isNotEmpty ? originalMsg : '未知错误,请重试';
}
}
///
Future<void> kr_resetSubscribePeriod() async {
if (kr_currentSubscribe.value == null) {
@ -444,12 +486,23 @@ class KRSubscribeService {
///
Future<void> kr_refreshAll() async {
try {
// 4 -
if (_isRefreshing) {
KRLogUtil.kr_w('⚠️ 正在刷新中,忽略重复请求', tag: 'SubscribeService');
return;
}
//
_isRefreshing = true;
KRLogUtil.kr_i('🔄 开始刷新订阅数据...', tag: 'SubscribeService');
// 🔧 2: -
if (!KRAppRunData().kr_isLogin.value) {
KRLogUtil.kr_e('❌ 未登录用户,无法刷新订阅数据', tag: 'SubscribeService');
kr_availableSubscribes.clear();
kr_currentSubscribe.value = null;
kr_currentStatus.value = KRSubscribeServiceStatus.kr_error;
_isRefreshing = false; //
return;
}
@ -462,8 +515,10 @@ class KRSubscribeService {
await kr_subscribeApi.kr_getAlreadySubscribe();
alreadySubscribeResult.fold(
(error) {
KRLogUtil.kr_e('获取已订阅列表失败: ${error.msg}', tag: 'SubscribeService');
throw Exception('获取已订阅列表失败: ${error.msg}');
// 5使
final friendlyMsg = _kr_getFriendlyErrorMessage(error.code, error.msg);
KRLogUtil.kr_e('获取已订阅列表失败: $friendlyMsg (错误码: ${error.code})', tag: 'SubscribeService');
throw Exception('获取已订阅列表失败: $friendlyMsg');
},
(subscribes) {
kr_alreadySubscribe.value = subscribes;
@ -486,7 +541,10 @@ class KRSubscribeService {
//
final subscribes = await subscribeResult.fold(
(error) {
throw Exception('获取可用订阅失败: ${error.msg}');
// 5使
final friendlyMsg = _kr_getFriendlyErrorMessage(error.code, error.msg);
KRLogUtil.kr_e('获取可用订阅失败: $friendlyMsg (错误码: ${error.code})', tag: 'SubscribeService');
throw Exception('获取可用订阅失败: $friendlyMsg');
},
(subscribes) => subscribes,
);
@ -579,7 +637,10 @@ class KRSubscribeService {
//
final nodes = await nodeResult.fold(
(error) {
throw Exception('获取节点列表失败: ${error.msg}');
// 5使
final friendlyMsg = _kr_getFriendlyErrorMessage(error.code, error.msg);
KRLogUtil.kr_e('获取节点列表失败: $friendlyMsg (错误码: ${error.code})', tag: 'SubscribeService');
throw Exception('获取节点列表失败: $friendlyMsg');
},
(nodes) => nodes,
);
@ -614,7 +675,10 @@ class KRSubscribeService {
} catch (err, stackTrace) {
kr_currentStatus.value = KRSubscribeServiceStatus.kr_error;
KRLogUtil.kr_e('刷新数据异常: $err\n$stackTrace', tag: 'SubscribeService');
rethrow;
} finally {
// 4
_isRefreshing = false;
KRLogUtil.kr_i('✅ 刷新完成,重置刷新标志', tag: 'SubscribeService');
}
}