自定义线路与线路优化
This commit is contained in:
@@ -7,6 +7,7 @@ import 'package:path_provider/path_provider.dart';
|
||||
import 'package:permission_handler/permission_handler.dart';
|
||||
import '../core/constants/storage_keys.dart';
|
||||
import '../data/models/download_task_model.dart';
|
||||
import 'custom_line_service.dart';
|
||||
import 'file_service.dart';
|
||||
import 'storage_service.dart';
|
||||
import '../core/utils/app_logger.dart';
|
||||
@@ -261,7 +262,14 @@ class DownloadService {
|
||||
await file.delete();
|
||||
}
|
||||
|
||||
return _startBdDownload(task, url, dir);
|
||||
final route = await CustomLineService.instance.routeDownloadUrl(url);
|
||||
if (route.changed) {
|
||||
AppLogger.d(
|
||||
'自定义线路下载代理已应用: node=${route.nodeName}, host=${route.originalHost}, proxy=${route.proxy?.proxyUri}',
|
||||
);
|
||||
}
|
||||
|
||||
return _startBdDownload(task, route.url, dir, headers: route.headers);
|
||||
} catch (e) {
|
||||
AppLogger.d('下载失败: $e');
|
||||
rethrow;
|
||||
@@ -272,12 +280,15 @@ class DownloadService {
|
||||
Future<String?> _startBdDownload(
|
||||
DownloadTaskModel task,
|
||||
String url,
|
||||
Directory dir,
|
||||
) async {
|
||||
Directory dir, {
|
||||
Map<String, String> headers = const {},
|
||||
}) async {
|
||||
await _configureCustomLineProxy();
|
||||
final wifiOnly = await isWifiOnlyEnabled();
|
||||
final retries = await getRetries();
|
||||
final bdTask = bd.DownloadTask(
|
||||
url: url,
|
||||
headers: headers,
|
||||
filename: task.fileName,
|
||||
directory: dir.path,
|
||||
baseDirectory: bd.BaseDirectory.root,
|
||||
@@ -340,10 +351,19 @@ class DownloadService {
|
||||
}
|
||||
|
||||
// 恢复任务:不删除部分文件,使用 resume 方式重建 bdTask
|
||||
final route = await CustomLineService.instance.routeDownloadUrl(url);
|
||||
if (route.changed) {
|
||||
AppLogger.d(
|
||||
'自定义线路下载代理已应用: node=${route.nodeName}, host=${route.originalHost}, proxy=${route.proxy?.proxyUri}',
|
||||
);
|
||||
}
|
||||
|
||||
await _configureCustomLineProxy();
|
||||
final wifiOnly = await isWifiOnlyEnabled();
|
||||
final retries = await getRetries();
|
||||
final bdTask = bd.DownloadTask(
|
||||
url: url,
|
||||
url: route.url,
|
||||
headers: route.headers,
|
||||
filename: task.fileName,
|
||||
directory: dir.path,
|
||||
baseDirectory: bd.BaseDirectory.root,
|
||||
@@ -382,6 +402,14 @@ class DownloadService {
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _configureCustomLineProxy() async {
|
||||
final endpoint = CustomLineService.instance.currentProxyEndpoint;
|
||||
final config = endpoint == null ? false : (endpoint.host, endpoint.port);
|
||||
await bd.FileDownloader().configure(
|
||||
globalConfig: (bd.Config.proxy, config),
|
||||
);
|
||||
}
|
||||
|
||||
/// 暂停下载
|
||||
Future<void> pauseDownload(String taskId) async {
|
||||
final bdTask = _bdTasks[taskId];
|
||||
|
||||
Reference in New Issue
Block a user