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

View file

@ -1,4 +1,7 @@
use crate::data::*;
use rocket::get;
#[get("/api?t=caps")]
pub(crate) fn caps() -> Result<String, String> {}
/// 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<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 {
/// Specify the ServerInfo to be listed in <server> for `/api?t=caps`
///
@ -10,7 +13,7 @@ pub struct ServerInfo {
pub version: Option<String>,
}
#[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<String>,
}
#[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<Subcategory>,
}
#[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<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.
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<bool, String> {
pub fn run(conf: data::Config, caps: data::Caps) -> Result<bool, String> {
/// Runs the server
rocket::build().mount("/", rocket::routes![api::caps]);
//rocket::build()
// .mount("/", rocket::routes![conf.caps])
// .launch();
return Ok(true);
}