From 66a0ecf5c1ae5562429f230af265f58ba55d7e65 Mon Sep 17 00:00:00 2001 From: Joel Wachsler Date: Sat, 6 Aug 2022 00:21:41 +0000 Subject: [PATCH] Fix priority parameter for filePrio --- qbittorrent-web-api-gen/api-4_1.md | 11 +++- qbittorrent-web-api-gen/groups.txt | 54 +++++++++++++++--- .../src/generate/api_group.rs | 3 +- qbittorrent-web-api-gen/src/generate/group.rs | 10 +++- qbittorrent-web-api-gen/src/types.rs | 9 ++- qbittorrent-web-api-gen/token_tree.txt | 57 ++++++++++++++++++- 6 files changed, 128 insertions(+), 16 deletions(-) diff --git a/qbittorrent-web-api-gen/api-4_1.md b/qbittorrent-web-api-gen/api-4_1.md index 1c44848..0b4cfea 100644 --- a/qbittorrent-web-api-gen/api-4_1.md +++ b/qbittorrent-web-api-gen/api-4_1.md @@ -2170,12 +2170,21 @@ Parameter | Type | Description ----------------------------------|---------|------------ `hash` | string | The hash of the torrent `id` | string | File ids, separated by `\|` -`priority` | number | File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values) +`priority` | object | priority object see table below. File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values) `id` values correspond to file position inside the array returned by [torrent contents API](#get-torrent-contents), e.g. `id=0` for first file, `id=1` for second file, etc. Since 2.8.2 it is reccomended to use `index` field returned by [torrent contents API](#get-torrent-contents) (since the files can be filtered and the `index` value may differ from the position inside the response array). +Possible values of `priority`: + +Value | Description +-----------|------------ +`0` | Do not download +`1` | Normal priority +`6` | High priority +`7` | Maximal priority + **Returns:** HTTP Status Code | Scenario diff --git a/qbittorrent-web-api-gen/groups.txt b/qbittorrent-web-api-gen/groups.txt index a693435..00654f3 100644 --- a/qbittorrent-web-api-gen/groups.txt +++ b/qbittorrent-web-api-gen/groups.txt @@ -5196,20 +5196,60 @@ is_list: false, }, ), - Number( - TypeInfo { - name: "priority", - description: Some( - "File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values)", + Object( + Object { + type_info: TypeInfo { + name: "priority", + description: Some( + "priority object see table below. File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values)", + ), + is_optional: false, + is_list: false, + }, + ref_type: String( + "Priority", ), - is_optional: false, - is_list: false, }, ), ], is_list: false, }, ), + Enum( + Enum { + name: "Priority", + values: [ + EnumValue { + description: Some( + "Do not download", + ), + value: "DoNotDownload", + original_value: "0", + }, + EnumValue { + description: Some( + "Normal priority", + ), + value: "NormalPriority", + original_value: "1", + }, + EnumValue { + description: Some( + "High priority", + ), + value: "HighPriority", + original_value: "6", + }, + EnumValue { + description: Some( + "Maximal priority", + ), + value: "MaximalPriority", + original_value: "7", + }, + ], + }, + ), ], }, }, diff --git a/qbittorrent-web-api-gen/src/generate/api_group.rs b/qbittorrent-web-api-gen/src/generate/api_group.rs index 0db717b..7452bb8 100644 --- a/qbittorrent-web-api-gen/src/generate/api_group.rs +++ b/qbittorrent-web-api-gen/src/generate/api_group.rs @@ -131,11 +131,12 @@ impl<'a> GroupGeneration<'a> { } fn all_derives(&self, derives: &'a [&'a str]) -> impl Iterator { - let base = vec!["serde::Deserialize", "Debug"].into_iter(); + let base = vec!["serde::Deserialize", "serde::Serialize", "Debug"].into_iter(); let additional = derives .iter() .copied() .filter(|item| item != &"serde::Deserialize") + .filter(|item| item != &"serde::Serialize") .filter(|item| item != &"Debug"); base.chain(additional) diff --git a/qbittorrent-web-api-gen/src/generate/group.rs b/qbittorrent-web-api-gen/src/generate/group.rs index 114fd32..ba8bd1c 100644 --- a/qbittorrent-web-api-gen/src/generate/group.rs +++ b/qbittorrent-web-api-gen/src/generate/group.rs @@ -199,9 +199,13 @@ impl types::Type { let name_str = self.name(); let name_snake = self.name_snake(); - quote! { - #add_to = #add_to.text(#name_str, #name_snake.to_string()); - } + let serialized = if self.is_object() { + quote! { serde_json::to_string(#name_snake).unwrap() } + } else { + quote! { #name_snake.to_string() } + }; + + quote! { #add_to = #add_to.text(#name_str, #serialized); } } fn generate_optional_builder_method(&self) -> TokenStream { diff --git a/qbittorrent-web-api-gen/src/types.rs b/qbittorrent-web-api-gen/src/types.rs index d2b70ef..e283b85 100644 --- a/qbittorrent-web-api-gen/src/types.rs +++ b/qbittorrent-web-api-gen/src/types.rs @@ -76,10 +76,17 @@ impl Type { Type::Bool(_) => "bool".into(), Type::String(_) => "str".into(), Type::StringArray(_) => "&[str]".into(), - Type::Object(_) => todo!(), + Type::Object(t) => match &t.ref_type { + RefType::String(s) => s.clone(), + _ => todo!(), + }, } } + pub fn is_object(&self) -> bool { + matches!(self, Type::Object(_)) + } + pub fn should_borrow(&self) -> bool { matches!(self, Type::String(_) | Type::Object(_)) } diff --git a/qbittorrent-web-api-gen/token_tree.txt b/qbittorrent-web-api-gen/token_tree.txt index 8b6feb8..df2e2a6 100644 --- a/qbittorrent-web-api-gen/token_tree.txt +++ b/qbittorrent-web-api-gen/token_tree.txt @@ -10235,11 +10235,11 @@ TokenTree { ], }, TableRow { - raw: "`priority` | number | File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values)", + raw: "`priority` | object | priority object see table below. File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values)", columns: [ "priority", - "number", - "File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values)", + "object", + "priority object see table below. File priority to set (consult [torrent contents API](#get-torrent-contents) for possible values)", ], }, ], @@ -10260,6 +10260,57 @@ TokenTree { Text( "", ), + Text( + "Possible values of `priority`:", + ), + Text( + "", + ), + Table( + Table { + header: TableRow { + raw: "Value | Description", + columns: [ + "Value", + "Description", + ], + }, + split: "-----------|------------", + rows: [ + TableRow { + raw: "`0` | Do not download", + columns: [ + "0", + "Do not download", + ], + }, + TableRow { + raw: "`1` | Normal priority", + columns: [ + "1", + "Normal priority", + ], + }, + TableRow { + raw: "`6` | High priority", + columns: [ + "6", + "High priority", + ], + }, + TableRow { + raw: "`7` | Maximal priority", + columns: [ + "7", + "Maximal priority", + ], + }, + ], + }, + ), + Text( + "", + ), Asterisk( "Returns:", ),