优化调整、BT下载(有bug)
This commit is contained in:
@@ -2,6 +2,17 @@ use serde::{Deserialize, Serialize};
|
||||
use specta::Type;
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// 任务下载协议类型
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Type, Default)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
pub enum TaskProtocol {
|
||||
/// HTTP/HTTPS 直链
|
||||
#[default]
|
||||
Http,
|
||||
/// BitTorrent(磁力链 / .torrent 文件)
|
||||
BitTorrent,
|
||||
}
|
||||
|
||||
/// 任务状态
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Type)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
@@ -16,6 +27,8 @@ pub enum TaskStatus {
|
||||
Complete,
|
||||
/// 错误
|
||||
Error,
|
||||
/// 已取消(用户取消:进度与文件已清除,仅保留记录,只能再次下载)
|
||||
Cancelled,
|
||||
}
|
||||
|
||||
/// 下载分段(多线程 Range 下载 / 断点续传用)
|
||||
@@ -52,18 +65,42 @@ impl Segment {
|
||||
}
|
||||
}
|
||||
|
||||
/// BT 种子内文件条目(多文件任务用;阶段1下载全部文件,但保留列表供 UI 展示)
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct BtFileInfo {
|
||||
/// 文件在种子内的索引
|
||||
pub index: u32,
|
||||
/// 相对种子根目录的路径(如 "sub/file.mkv")
|
||||
pub path: String,
|
||||
/// 文件大小(字节)
|
||||
pub size: u64,
|
||||
}
|
||||
|
||||
/// 下载任务
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, Type)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct DownloadTask {
|
||||
/// 任务 ID(自增 hex 字符串)
|
||||
pub id: String,
|
||||
/// 下载地址
|
||||
/// 下载地址(HTTP URL 或磁力链接)
|
||||
pub url: String,
|
||||
/// 文件名
|
||||
/// 文件名(HTTP:目标文件名;BT:种子名称)
|
||||
pub filename: String,
|
||||
/// 保存目录(绝对路径)
|
||||
pub dir: String,
|
||||
/// 协议类型
|
||||
#[serde(default)]
|
||||
pub protocol: TaskProtocol,
|
||||
/// BT 种子 infohash(协议=BitTorrent 时存在)
|
||||
#[serde(default)]
|
||||
pub info_hash: Option<String>,
|
||||
/// BT 种子内文件列表(协议=BitTorrent 时存在)
|
||||
#[serde(default)]
|
||||
pub bt_files: Vec<BtFileInfo>,
|
||||
/// BT 元数据是否已解析就绪(异步添加时:后台解析完成前为 false,调度器跳过)
|
||||
#[serde(default)]
|
||||
pub bt_metadata_ready: bool,
|
||||
/// 状态
|
||||
pub status: TaskStatus,
|
||||
/// 文件总大小(字节),0=未知
|
||||
@@ -141,6 +178,18 @@ pub struct DownloaderSettings {
|
||||
/// 下载是否使用代理:true=尊重系统代理(mihomo 开启系统代理时经其转发),false=强制直连
|
||||
#[serde(default = "default_true")]
|
||||
pub use_proxy: bool,
|
||||
/// BitTorrent 上传限速 KB/s(0=不限)
|
||||
#[serde(default)]
|
||||
pub bt_upload_limit_kb: u64,
|
||||
/// BitTorrent 下载完成后是否继续做种上传(false=下载完即停止上传)
|
||||
#[serde(default)]
|
||||
pub bt_seed_after_download: bool,
|
||||
/// BitTorrent 监听端口(0=自动选择)
|
||||
#[serde(default)]
|
||||
pub bt_listen_port: u16,
|
||||
/// BitTorrent 使用代理下载:开启后自动使用代理模块(mihomo)的 SOCKS5 端口;代理不可用时降级直连
|
||||
#[serde(default)]
|
||||
pub bt_use_proxy: bool,
|
||||
}
|
||||
|
||||
fn default_max_concurrent() -> u32 {
|
||||
@@ -180,6 +229,10 @@ impl Default for DownloaderSettings {
|
||||
delete_files_on_remove: false,
|
||||
check_duplicate: true,
|
||||
use_proxy: true,
|
||||
bt_upload_limit_kb: 0,
|
||||
bt_seed_after_download: false,
|
||||
bt_listen_port: 0,
|
||||
bt_use_proxy: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user