diff --git a/Cargo.lock b/Cargo.lock index 8f5d35c..5861e8c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -729,9 +729,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.91" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307e3004becf10f5a6e0d59d20f3cd28231b0e0827a96cd3e0ce6d14bc1e4bb3" +checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0" dependencies = [ "unicode-ident", ] @@ -1255,6 +1255,7 @@ name = "torznab-toolkit" version = "0.1.0" dependencies = [ "rocket", + "xml", ] [[package]] @@ -1567,6 +1568,21 @@ dependencies = [ "memchr", ] +[[package]] +name = "xml" +version = "0.8.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ede1c99c55b4b3ad0349018ef0eccbe954ce9c342334410707ee87177fcf2ab4" +dependencies = [ + "xml-rs", +] + +[[package]] +name = "xml-rs" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af310deaae937e48a26602b730250b4949e125f468f11e6990be3e5304ddd96f" + [[package]] name = "yansi" version = "1.0.1" diff --git a/Cargo.toml b/Cargo.toml index fa9673a..597e3a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,4 @@ edition = "2021" [dependencies] rocket = "0.5.1" +xml = "0.8.20" diff --git a/src/api.rs b/src/api.rs index 6a2e6f0..fae11ff 100644 --- a/src/api.rs +++ b/src/api.rs @@ -1,4 +1,7 @@ +use crate::data::*; use rocket::get; -#[get("/api?t=caps")] -pub(crate) fn caps() -> Result {} +/// A struct that holds configuration for torznab-toolkit +/// A search function (/api?t=search) and capabilities (/api?t=caps - struct Caps) required +/// Everything else is optional +pub static mut config: Option = None; diff --git a/src/config.rs b/src/config.rs deleted file mode 100644 index 84b880e..0000000 --- a/src/config.rs +++ /dev/null @@ -1,51 +0,0 @@ -use crate::data::*; - -type AuthFunc = fn(String) -> Result; -type SearchFunc = fn(String, Vec) -> Result; - -#[derive(Debug)] -pub struct Config { - /// A struct that holds configuration for torznab-toolkit - /// A search function (/api?t=search) and capabilities (/api?t=caps - struct Caps) required - /// Everything else is optional - pub search: SearchFunc, - pub auth: Option, - pub caps: Caps, - pub tvsearch: Option, - pub movie: Option, - pub music: Option, - pub book: Option, -} - -#[derive(Debug)] -pub struct Caps { - /// Holds the configuration for the capabilities of the Torznab server - /// - /// - server_info: `ServerInfo` - /// - see: `ServerInfo` docs - /// - limits: `Limits` - /// - specifies the max and default items listed when searching - /// - see: `Limits` docs - /// - searching: `Vec` - /// - specifies the capabilities of each search mode - /// - see: `SearchInfo` docs - /// - categories: `Vec` - /// - lists known categories - /// - see: `Category` docs - /// - genres: `Option>` - /// - lists known genres, optional - /// - see: `Genre` docs - /// - ///
Note that this library might not support all the capabilities listed in yet, so check the README before listing capabilities, or just accept that unsupported capabilities will return error 404. - /// - /// It's recommended to add any capabilities you want, and set `available` to `false` in the `Caps` struct for any currently unsupported search types.
- /// - /// - /// TODO: Add a way to partially generate search capabilities automatically from the Config - pub server_info: ServerInfo, - pub limits: Limits, - pub searching: Vec, - pub categories: Vec, - pub genres: Option>, - pub tags: Option>, -} diff --git a/src/data.rs b/src/data.rs index 93970cc..f001577 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,4 +1,7 @@ -#[derive(Debug)] +pub(crate) type AuthFunc = fn(String) -> Result; +pub(crate) type SearchFunc = fn(String, Vec) -> Result; + +#[derive(Debug, Clone)] pub struct ServerInfo { /// Specify the ServerInfo to be listed in for `/api?t=caps` /// @@ -10,7 +13,7 @@ pub struct ServerInfo { pub version: Option, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Limits { /// The maximum and defaults for the `limit` parameter in queries /// `max` is the maximum number of results the program can return @@ -24,7 +27,7 @@ pub struct Limits { pub default: u64, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct SearchInfo { /// A struct holding the info for a type of search /// - `search_type` must be `search`, `tv-search`, `movie-search`, `audio-search`, or `book-search` @@ -34,29 +37,76 @@ pub struct SearchInfo { pub supported_params: Vec, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Subcategory { pub id: String, pub name: String, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Category { pub id: String, pub name: String, pub subcategories: Vec, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Genre { pub id: String, pub category_id: String, pub name: String, } -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct Tag { pub id: String, pub category_id: String, pub name: String, } + +#[derive(Debug, Clone)] +pub struct Caps { + /// Holds the configuration for the capabilities of the Torznab server + /// + /// - server_info: `ServerInfo` + /// - see: `ServerInfo` docs + /// - limits: `Limits` + /// - specifies the max and default items listed when searching + /// - see: `Limits` docs + /// - searching: `Vec` + /// - specifies the capabilities of each search mode + /// - see: `SearchInfo` docs + /// - categories: `Vec` + /// - lists known categories + /// - see: `Category` docs + /// - genres: `Option>` + /// - lists known genres, optional + /// - see: `Genre` docs + /// + ///
Note that this library might not support all the capabilities listed in yet, so check the README before listing capabilities, or just accept that unsupported capabilities will return error 404. + /// + /// It's recommended to add any capabilities you want, and set `available` to `false` in the `Caps` struct for any currently unsupported search types.
+ /// + /// + /// TODO: Add a way to partially(?) generate automatically from the Config + pub server_info: ServerInfo, + pub limits: Limits, + pub searching: Vec, + pub categories: Vec, + pub genres: Option>, + pub tags: Option>, +} + +#[derive(Debug, Clone)] +pub struct Config { + /// A struct that holds configuration for torznab-toolkit + /// A search function (/api?t=search) and capabilities (/api?t=caps - struct Caps) required + /// Everything else is optional + pub search: SearchFunc, // NOTE: This is NOT optional, + pub auth: Option, + pub caps: Caps, + pub tvsearch: Option, + pub movie: Option, + pub music: Option, + pub book: Option, +} diff --git a/src/lib.rs b/src/lib.rs index 60eb499..99fbe4e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,15 +18,15 @@ //! //! Note: I wrote the line above when I was tired. Don't ask me what *literal* truckloads of structs means, I don't know either. -mod api; -pub mod config; +pub mod api; pub mod data; -use config::{Caps, Config}; -use rocket; +use rocket::{self}; -pub fn run(config: Config, caps: Caps) -> Result { +pub fn run(conf: data::Config, caps: data::Caps) -> Result { /// Runs the server - rocket::build().mount("/", rocket::routes![api::caps]); + //rocket::build() + // .mount("/", rocket::routes![conf.caps]) + // .launch(); return Ok(true); }