use super::checksum::ExpectedChecksum;
use super::options::DownloadPriority;
use super::torrent::{PeerInfo, TorrentStatusInfo};
use super::types::{DownloadId, DownloadKind, DownloadProgress, DownloadState};
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DownloadMetadata {
pub name: String,
pub url: Option<String>,
pub magnet_uri: Option<String>,
pub info_hash: Option<String>,
pub save_dir: PathBuf,
pub filename: Option<String>,
pub user_agent: Option<String>,
pub referer: Option<String>,
pub headers: Vec<(String, String)>,
#[serde(default)]
pub cookies: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub checksum: Option<ExpectedChecksum>,
#[serde(default)]
pub mirrors: Vec<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub etag: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub last_modified: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DownloadStatus {
pub id: DownloadId,
pub kind: DownloadKind,
pub state: DownloadState,
#[serde(default)]
pub priority: DownloadPriority,
pub progress: DownloadProgress,
pub metadata: DownloadMetadata,
#[serde(skip_serializing_if = "Option::is_none")]
pub torrent_info: Option<TorrentStatusInfo>,
#[serde(skip_serializing_if = "Option::is_none")]
pub peers: Option<Vec<PeerInfo>>,
pub created_at: DateTime<Utc>,
pub completed_at: Option<DateTime<Utc>>,
}
impl DownloadStatus {
pub fn gid(&self) -> String {
self.id.to_gid()
}
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct GlobalStats {
pub download_speed: u64,
pub upload_speed: u64,
pub num_active: usize,
pub num_waiting: usize,
pub num_stopped: usize,
}