Skip to main content

qbit_rs/endpoint/
sync.rs

1use serde::Serialize;
2use serde_with::skip_serializing_none;
3
4use crate::{Qbit, Result, ext::*, model::*};
5
6impl Qbit {
7    /// Return main-data changes since the supplied response ID.
8    pub async fn sync(&self, rid: impl Into<Option<i64>> + Send + Sync) -> Result<SyncData> {
9        #[derive(Serialize)]
10        #[skip_serializing_none]
11        struct Arg {
12            rid: Option<i64>,
13        }
14
15        self.get_with("sync/maindata", &Arg { rid: rid.into() })
16            .await?
17            .json()
18            .await
19            .map_err(Into::into)
20    }
21
22    /// Return peer-data changes for a torrent since the supplied response ID.
23    pub async fn get_torrent_peers(
24        &self,
25        hash: impl AsRef<str> + Send + Sync,
26        rid: impl Into<Option<i64>> + Send + Sync,
27    ) -> Result<PeerSyncData> {
28        #[derive(Serialize)]
29        struct Arg<'a> {
30            hash: &'a str,
31            rid: Option<i64>,
32        }
33
34        self.get_with(
35            "sync/torrentPeers",
36            &Arg {
37                hash: hash.as_ref(),
38                rid: rid.into(),
39            },
40        )
41        .await
42        .and_then(|r| r.map_status(TORRENT_NOT_FOUND))?
43        .json()
44        .await
45        .map_err(Into::into)
46    }
47}