Skip to main content

torbox_ddl_rs/
query.rs

1use crate::types::FormatType;
2use serde::Serialize;
3
4#[derive(Debug, Serialize)]
5#[cfg_attr(feature = "specta", derive(specta::Type))]
6pub struct WebdownloadRequestLinkQuery {
7    /// Hidden and not shown by specta because token is needed for queries here :(
8    #[cfg_attr(feature = "specta", specta(skip))]
9    pub(crate) token: String,
10    /// The torrent's ID that you want to download
11    pub web_id: u32,
12    /// The files's ID that you want to download.
13    pub files_id: Option<Vec<u32>>,
14    /// If you want a zip link. Required if no file_id. Takes precedence over file_id if both are given.
15    pub zip_link: bool,
16    /// The user's IP to determine the closest CDN. Optional.
17    ///
18    /// Preferably check IPv4 if correct first.
19    pub user_ip: Option<String>,
20    /// If you want to redirect the user to the CDN link.
21    ///
22    /// This is useful for creating permalinks so that you can just make this request URL the link.
23    pub redirect: bool,
24}
25
26impl Default for WebdownloadRequestLinkQuery {
27    fn default() -> Self {
28        Self {
29            token: String::new(),
30            web_id: 0,
31            files_id: None,
32            zip_link: false,
33            user_ip: None,
34            redirect: false,
35        }
36    }
37}
38
39#[derive(Debug, Serialize)]
40#[cfg_attr(feature = "specta", derive(specta::Type))]
41pub struct WebdownloadControlQuery {
42    pub bypass_cache: bool,
43}
44
45impl Default for WebdownloadControlQuery {
46    fn default() -> Self {
47        Self {
48            bypass_cache: false,
49        }
50    }
51}
52
53/// `id` param isn't given because if it is, it will return an Object and not a Vec
54///
55/// Please use TorrentStatusQuery instead
56#[derive(Debug, Serialize)]
57#[cfg_attr(feature = "specta", derive(specta::Type))]
58pub struct ListWebdownloadsQuery {
59    id: Option<u32>,
60    /// Allows you to bypass the cached data, and always get fresh information.
61    ///
62    /// Useful if constantly querying for fresh download stats.
63    /// Otherwise, we request that you save our database a few calls.
64    pub bypass_cache: Option<bool>,
65    /// Determines the offset of items to get from the database.
66    ///
67    /// Default is 0. Optional.
68    pub offset: Option<u32>,
69    /// Determines the number of items to recieve per request.
70    ///
71    /// Default is 1000. Optional.
72    pub limit: Option<u32>,
73}
74
75impl Default for ListWebdownloadsQuery {
76    fn default() -> Self {
77        Self {
78            id: None,
79            bypass_cache: None,
80            offset: None,
81            limit: None,
82        }
83    }
84}
85
86#[derive(Debug, Serialize)]
87#[cfg_attr(feature = "specta", derive(specta::Type))]
88pub struct WebdownloadCachedAvailabilityQuery {
89    #[serde(serialize_with = "serialize_comma_separated")]
90    pub hash: Vec<String>,
91    pub format: FormatType,
92}
93
94fn serialize_comma_separated<S>(vec: &[String], serializer: S) -> Result<S::Ok, S::Error>
95where
96    S: serde::Serializer,
97{
98    serializer.serialize_str(&vec.join(","))
99}
100
101impl Default for WebdownloadCachedAvailabilityQuery {
102    fn default() -> Self {
103        Self {
104            hash: Vec::new(),
105            format: FormatType::List,
106        }
107    }
108}