gosh_dl/protocol/
status.rs

1//! Download status types
2//!
3//! Types for representing the current state of downloads.
4
5use super::checksum::ExpectedChecksum;
6use super::options::DownloadPriority;
7use super::torrent::{PeerInfo, TorrentStatusInfo};
8use super::types::{DownloadId, DownloadKind, DownloadProgress, DownloadState};
9use chrono::{DateTime, Utc};
10use serde::{Deserialize, Serialize};
11use std::path::PathBuf;
12
13/// Metadata about a download
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct DownloadMetadata {
16    /// Display name
17    pub name: String,
18    /// Original URL (for HTTP)
19    pub url: Option<String>,
20    /// Magnet URI (for magnet links)
21    pub magnet_uri: Option<String>,
22    /// Info hash (for torrents)
23    pub info_hash: Option<String>,
24    /// Save directory
25    pub save_dir: PathBuf,
26    /// Output filename (may differ from name for multi-file torrents)
27    pub filename: Option<String>,
28    /// Custom user agent
29    pub user_agent: Option<String>,
30    /// Custom referer
31    pub referer: Option<String>,
32    /// Custom headers
33    pub headers: Vec<(String, String)>,
34    /// Cookies for authenticated downloads
35    #[serde(default)]
36    pub cookies: Vec<String>,
37    /// Expected checksum for verification (HTTP only)
38    #[serde(skip_serializing_if = "Option::is_none")]
39    pub checksum: Option<ExpectedChecksum>,
40    /// Mirror/fallback URLs (HTTP only)
41    #[serde(default)]
42    pub mirrors: Vec<String>,
43    /// ETag for resume validation (HTTP only)
44    #[serde(skip_serializing_if = "Option::is_none")]
45    pub etag: Option<String>,
46    /// Last-Modified for resume validation (HTTP only)
47    #[serde(skip_serializing_if = "Option::is_none")]
48    pub last_modified: Option<String>,
49}
50
51/// Full status of a download
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct DownloadStatus {
54    /// Unique identifier
55    pub id: DownloadId,
56    /// Type of download
57    pub kind: DownloadKind,
58    /// Current state
59    pub state: DownloadState,
60    /// Download priority
61    #[serde(default)]
62    pub priority: DownloadPriority,
63    /// Progress information
64    pub progress: DownloadProgress,
65    /// Metadata
66    pub metadata: DownloadMetadata,
67    /// Torrent-specific info (only for torrent/magnet downloads)
68    #[serde(skip_serializing_if = "Option::is_none")]
69    pub torrent_info: Option<TorrentStatusInfo>,
70    /// Connected peers (only for torrent downloads)
71    #[serde(skip_serializing_if = "Option::is_none")]
72    pub peers: Option<Vec<PeerInfo>>,
73    /// When the download was created
74    pub created_at: DateTime<Utc>,
75    /// When the download completed (if completed)
76    pub completed_at: Option<DateTime<Utc>>,
77}
78
79impl DownloadStatus {
80    /// Get GID for frontend compatibility
81    pub fn gid(&self) -> String {
82        self.id.to_gid()
83    }
84}
85
86/// Global statistics
87#[derive(Debug, Clone, Default, Serialize, Deserialize)]
88pub struct GlobalStats {
89    /// Total download speed
90    pub download_speed: u64,
91    /// Total upload speed
92    pub upload_speed: u64,
93    /// Number of active downloads
94    pub num_active: usize,
95    /// Number of waiting downloads
96    pub num_waiting: usize,
97    /// Number of stopped downloads
98    pub num_stopped: usize,
99}