mirror of
https://github.com/kristoferssolo/transmission-rpc.git
synced 2025-10-21 20:10:37 +00:00
rebase
This commit is contained in:
parent
fc0f3bd023
commit
cf97ab0eea
2
.github/workflows/ci.yml
vendored
2
.github/workflows/ci.yml
vendored
@ -39,7 +39,7 @@ jobs:
|
||||
with:
|
||||
command: build
|
||||
|
||||
- name: Setup Test Enviroment
|
||||
- name: Setup Test Environment
|
||||
run: docker-compose up -d
|
||||
|
||||
- name: Cargo Test
|
||||
|
||||
@ -17,7 +17,7 @@ reqwest = { version = "0.11.11", features = [
|
||||
"rustls-tls",
|
||||
], default-features = false }
|
||||
serde = { version = "1.0.144", features = ["derive"] }
|
||||
enum-iterator = "1.2.0"
|
||||
enum-iterator = "0.8.1"
|
||||
|
||||
dotenv = "0.15.0"
|
||||
log = "0.4.17"
|
||||
|
||||
19
src/lib.rs
19
src/lib.rs
@ -12,7 +12,8 @@ pub mod types;
|
||||
use types::{
|
||||
BasicAuth, BlocklistUpdate, FreeSpace, Id, Nothing, PortTest, Result, RpcRequest, RpcResponse,
|
||||
RpcResponseArgument, SessionClose, SessionGet, SessionStats, Torrent, TorrentAction,
|
||||
TorrentAddArgs, TorrentAddedOrDuplicate, TorrentGetField, TorrentRenamePath, Torrents,
|
||||
TorrentAddArgs, TorrentAddedOrDuplicate, TorrentGetField, TorrentRenamePath, TorrentSetArgs,
|
||||
Torrents,
|
||||
};
|
||||
|
||||
const MAX_RETRIES: usize = 5;
|
||||
@ -381,9 +382,9 @@ impl TransClient {
|
||||
///
|
||||
/// let args = TorrentSetArgs {
|
||||
/// labels: Some(vec![String::from("blue")]),
|
||||
/// ..Default::default(),
|
||||
/// ..Default::default()
|
||||
/// };
|
||||
/// assert!(client.torrent_set(args, vec![Id::Id(0)]).await?.is_ok())
|
||||
/// assert!(client.torrent_set(args, Some(vec![Id::Id(0)])).await?.is_ok());
|
||||
///
|
||||
/// Ok(())
|
||||
/// }
|
||||
@ -636,12 +637,12 @@ impl TransClient {
|
||||
|
||||
let rsp: reqwest::Response = rq.send().await?;
|
||||
if matches!(rsp.status(), StatusCode::CONFLICT) {
|
||||
let session_id = rsp
|
||||
.headers()
|
||||
.get("X-Transmission-Session-Id")
|
||||
.ok_or(TransError::NoSessionIdReceived)?
|
||||
.to_str()?;
|
||||
self.session_id = Some(String::from(session_id));
|
||||
let session_id = rsp
|
||||
.headers()
|
||||
.get("X-Transmission-Session-Id")
|
||||
.ok_or(TransError::NoSessionIdReceived)?
|
||||
.to_str()?;
|
||||
self.session_id = Some(String::from(session_id));
|
||||
|
||||
info!("Got new session_id: {}. Retrying request.", session_id);
|
||||
} else {
|
||||
|
||||
@ -12,6 +12,7 @@ pub struct BasicAuth {
|
||||
pub(crate) use self::request::RpcRequest;
|
||||
pub use self::request::{
|
||||
ArgumentFields, Id, TorrentAction, TorrentAddArgs, TorrentGetField, TorrentRenamePathArgs,
|
||||
TorrentSetArgs,
|
||||
};
|
||||
|
||||
pub(crate) use self::response::RpcResponseArgument;
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
use enum_iterator::{all, Sequence};
|
||||
use enum_iterator::IntoEnumIterator;
|
||||
use serde::Serialize;
|
||||
|
||||
#[derive(Serialize, Debug)]
|
||||
@ -53,7 +53,7 @@ impl RpcRequest {
|
||||
|
||||
pub fn torrent_get(fields: Option<Vec<TorrentGetField>>, ids: Option<Vec<Id>>) -> RpcRequest {
|
||||
let string_fields = fields
|
||||
.unwrap_or(all::<TorrentGetField>().collect())
|
||||
.unwrap_or(TorrentGetField::all())
|
||||
.iter()
|
||||
.map(TorrentGetField::to_str)
|
||||
.collect();
|
||||
@ -70,7 +70,7 @@ impl RpcRequest {
|
||||
args.ids = ids;
|
||||
RpcRequest {
|
||||
method: String::from("torrent-set"),
|
||||
arguments: Some(Args::TorrentSetArgs(args)),
|
||||
arguments: Some(Args::TorrentSet(args)),
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,6 +135,7 @@ pub enum Args {
|
||||
TorrentAction(TorrentActionArgs),
|
||||
TorrentRemove(TorrentRemoveArgs),
|
||||
TorrentAdd(TorrentAddArgs),
|
||||
TorrentSet(TorrentSetArgs),
|
||||
TorrentSetLocation(TorrentSetLocationArgs),
|
||||
TorrentRenamePath(TorrentRenamePathArgs),
|
||||
}
|
||||
@ -154,7 +155,9 @@ pub struct TorrentGetArgs {
|
||||
|
||||
impl Default for TorrentGetArgs {
|
||||
fn default() -> Self {
|
||||
let all_fields = all::<TorrentGetField>().map(|it| it.to_str()).collect();
|
||||
let all_fields = TorrentGetField::into_enum_iter()
|
||||
.map(|it| it.to_str())
|
||||
.collect();
|
||||
TorrentGetArgs {
|
||||
fields: Some(all_fields),
|
||||
ids: None,
|
||||
@ -195,7 +198,7 @@ pub enum Id {
|
||||
Hash(String),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Debug, Default, Clone, Default)]
|
||||
#[derive(Serialize, Debug, Clone, Default)]
|
||||
pub struct TorrentAddArgs {
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub cookies: Option<String>,
|
||||
@ -236,7 +239,7 @@ pub struct TorrentAddArgs {
|
||||
pub labels: Option<Vec<String>>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Sequence)]
|
||||
#[derive(Clone, Copy, IntoEnumIterator)]
|
||||
pub enum TorrentGetField {
|
||||
ActivityDate,
|
||||
AddedDate,
|
||||
@ -280,6 +283,10 @@ pub enum TorrentGetField {
|
||||
}
|
||||
|
||||
impl TorrentGetField {
|
||||
pub fn all() -> Vec<TorrentGetField> {
|
||||
TorrentGetField::into_enum_iter().collect()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn to_str(&self) -> String {
|
||||
match self {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user