set up layout for the module

Co-authored-by: confused-ace-noises <confused-ace-noises@users.noreply.github.com>
This commit is contained in:
askiiart 2024-11-23 18:39:48 -06:00
parent 4a7dc28893
commit cdb0a82181
Signed by untrusted user who does not match committer: askiiart
GPG key ID: EA85979611654C30
6 changed files with 87 additions and 68 deletions

20
Cargo.lock generated
View file

@ -729,9 +729,9 @@ dependencies = [
[[package]] [[package]]
name = "proc-macro2" name = "proc-macro2"
version = "1.0.91" version = "1.0.92"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "307e3004becf10f5a6e0d59d20f3cd28231b0e0827a96cd3e0ce6d14bc1e4bb3" checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
dependencies = [ dependencies = [
"unicode-ident", "unicode-ident",
] ]
@ -1255,6 +1255,7 @@ name = "torznab-toolkit"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"rocket", "rocket",
"xml",
] ]
[[package]] [[package]]
@ -1567,6 +1568,21 @@ dependencies = [
"memchr", "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]] [[package]]
name = "yansi" name = "yansi"
version = "1.0.1" version = "1.0.1"

View file

@ -5,3 +5,4 @@ edition = "2021"
[dependencies] [dependencies]
rocket = "0.5.1" rocket = "0.5.1"
xml = "0.8.20"

View file

@ -1,4 +1,7 @@
use crate::data::*;
use rocket::get; use rocket::get;
#[get("/api?t=caps")] /// A struct that holds configuration for torznab-toolkit
pub(crate) fn caps() -> Result<String, String> {} /// A search function (/api?t=search) and capabilities (/api?t=caps - struct Caps) required
/// Everything else is optional
pub static mut config: Option<Config> = None;

View file

@ -1,51 +0,0 @@
use crate::data::*;
type AuthFunc = fn(String) -> Result<String, String>;
type SearchFunc = fn(String, Vec<String>) -> Result<String, String>;
#[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<AuthFunc>,
pub caps: Caps,
pub tvsearch: Option<SearchFunc>,
pub movie: Option<SearchFunc>,
pub music: Option<SearchFunc>,
pub book: Option<SearchFunc>,
}
#[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<SearchInfo>`
/// - specifies the capabilities of each search mode
/// - see: `SearchInfo` docs
/// - categories: `Vec<Category>`
/// - lists known categories
/// - see: `Category` docs
/// - genres: `Option<Vec<Genre>>`
/// - lists known genres, optional
/// - see: `Genre` docs
///
/// <div class="warning">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.</div>
///
///
/// TODO: Add a way to partially generate search capabilities automatically from the Config
pub server_info: ServerInfo,
pub limits: Limits,
pub searching: Vec<SearchInfo>,
pub categories: Vec<Category>,
pub genres: Option<Vec<Genre>>,
pub tags: Option<Vec<Tag>>,
}

View file

@ -1,4 +1,7 @@
#[derive(Debug)] pub(crate) type AuthFunc = fn(String) -> Result<String, String>;
pub(crate) type SearchFunc = fn(String, Vec<String>) -> Result<String, String>;
#[derive(Debug, Clone)]
pub struct ServerInfo { pub struct ServerInfo {
/// Specify the ServerInfo to be listed in <server> for `/api?t=caps` /// Specify the ServerInfo to be listed in <server> for `/api?t=caps`
/// ///
@ -10,7 +13,7 @@ pub struct ServerInfo {
pub version: Option<String>, pub version: Option<String>,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Limits { pub struct Limits {
/// The maximum and defaults for the `limit` parameter in queries /// The maximum and defaults for the `limit` parameter in queries
/// `max` is the maximum number of results the program can return /// `max` is the maximum number of results the program can return
@ -24,7 +27,7 @@ pub struct Limits {
pub default: u64, pub default: u64,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct SearchInfo { pub struct SearchInfo {
/// A struct holding the info for a type of search /// A struct holding the info for a type of search
/// - `search_type` must be `search`, `tv-search`, `movie-search`, `audio-search`, or `book-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<String>, pub supported_params: Vec<String>,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Subcategory { pub struct Subcategory {
pub id: String, pub id: String,
pub name: String, pub name: String,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Category { pub struct Category {
pub id: String, pub id: String,
pub name: String, pub name: String,
pub subcategories: Vec<Subcategory>, pub subcategories: Vec<Subcategory>,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Genre { pub struct Genre {
pub id: String, pub id: String,
pub category_id: String, pub category_id: String,
pub name: String, pub name: String,
} }
#[derive(Debug)] #[derive(Debug, Clone)]
pub struct Tag { pub struct Tag {
pub id: String, pub id: String,
pub category_id: String, pub category_id: String,
pub name: 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<SearchInfo>`
/// - specifies the capabilities of each search mode
/// - see: `SearchInfo` docs
/// - categories: `Vec<Category>`
/// - lists known categories
/// - see: `Category` docs
/// - genres: `Option<Vec<Genre>>`
/// - lists known genres, optional
/// - see: `Genre` docs
///
/// <div class="warning">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.</div>
///
///
/// TODO: Add a way to partially(?) generate automatically from the Config
pub server_info: ServerInfo,
pub limits: Limits,
pub searching: Vec<SearchInfo>,
pub categories: Vec<Category>,
pub genres: Option<Vec<Genre>>,
pub tags: Option<Vec<Tag>>,
}
#[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<AuthFunc>,
pub caps: Caps,
pub tvsearch: Option<SearchFunc>,
pub movie: Option<SearchFunc>,
pub music: Option<SearchFunc>,
pub book: Option<SearchFunc>,
}

View file

@ -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. //! 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 api;
pub mod config;
pub mod data; pub mod data;
use config::{Caps, Config}; use rocket::{self};
use rocket;
pub fn run(config: Config, caps: Caps) -> Result<bool, String> { pub fn run(conf: data::Config, caps: data::Caps) -> Result<bool, String> {
/// Runs the server /// Runs the server
rocket::build().mount("/", rocket::routes![api::caps]); //rocket::build()
// .mount("/", rocket::routes![conf.caps])
// .launch();
return Ok(true); return Ok(true);
} }