clean up docs a bit, and remove InternalSearchParameters as it was unneeded
This commit is contained in:
parent
e4de416464
commit
3e37af540e
4 changed files with 18 additions and 93 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
A safe, multi-threaded, async toolkit for adding Torznab APIs to programs. You just focus on the indexer itself, we abstract away the hell that is the Torznab API.
|
||||
|
||||
Just fill in your own relevant functions and config, and torznab-toolkit will run the API for you
|
||||
Just fill in your own relevant functions and config ([`Config`]), and torznab-toolkit will run the API for you
|
||||
|
||||
```rust
|
||||
use torznab_toolkit;
|
||||
|
@ -11,7 +11,7 @@ let config: torznab_toolkit::config::Config = /* config goes here */
|
|||
torznab_toolkit::run(config);
|
||||
```
|
||||
|
||||
The environment variables `ROCKET_ADDRESS` and `ROCKET_PORT` specify the address and port it will run on; these currently cannot be configured any other way. See the [relevant docs](https://rocket.rs/guide/v0.5/deploying/) for details.
|
||||
To configure what it listens on, just change `ROCKET_ADDRESS` and `ROCKET_PORT`; see the [relevant docs](https://rocket.rs/guide/v0.5/deploying/) for details.
|
||||
|
||||
---
|
||||
|
||||
|
|
65
src/api.rs
65
src/api.rs
|
@ -32,7 +32,7 @@ struct SearchForm {
|
|||
|
||||
impl SearchForm {
|
||||
/// Converts it to a SearchParameters object
|
||||
fn to_parameters(&self, conf: Config) -> InternalSearchParameters {
|
||||
fn to_parameters(&self, conf: Config, search_type: &str) -> SearchParameters {
|
||||
let mut categories: Option<Vec<u32>> = None;
|
||||
if !self.cat.is_none() {
|
||||
// unholy amalgation of code to make the comma-separated list of strings into a vector of integers
|
||||
|
@ -71,7 +71,8 @@ impl SearchForm {
|
|||
limit = 1
|
||||
}
|
||||
|
||||
return InternalSearchParameters {
|
||||
return SearchParameters {
|
||||
search_type: search_type.to_string(),
|
||||
q: self.q.clone(),
|
||||
apikey: self.apikey.clone(),
|
||||
categories: categories,
|
||||
|
@ -212,12 +213,12 @@ pub(crate) async fn search(
|
|||
form: SearchForm,
|
||||
) -> status::Custom<RawXml<String>> {
|
||||
// oh god this is horrible but it works
|
||||
let parameters = form.to_parameters((**conf).clone());
|
||||
let parameters = form.to_parameters((**conf).clone(), "search");
|
||||
|
||||
let mut unauthorized = false;
|
||||
match conf.auth {
|
||||
Some(auth) => {
|
||||
match parameters.clone().apikey {
|
||||
match parameters.apikey.clone() {
|
||||
Some(apikey) => {
|
||||
if !auth(apikey).unwrap() {
|
||||
unauthorized = true;
|
||||
|
@ -236,9 +237,7 @@ pub(crate) async fn search(
|
|||
return status::Custom(Status::Unauthorized, RawXml("401 Unauthorized".to_string()));
|
||||
}
|
||||
|
||||
let search_parameters: SearchParameters = parameters.to_search_param("search");
|
||||
|
||||
return search_handler(conf, search_parameters).await;
|
||||
return search_handler(conf, parameters).await;
|
||||
}
|
||||
|
||||
#[get("/api?t=tvsearch&<form..>", rank = 3)]
|
||||
|
@ -248,7 +247,7 @@ pub(crate) async fn tv_search(
|
|||
form: SearchForm,
|
||||
) -> status::Custom<RawXml<String>> {
|
||||
// oh god this is horrible but it works
|
||||
let parameters = form.to_parameters((**conf).clone());
|
||||
let parameters = form.to_parameters((**conf).clone(), "tv-search");
|
||||
|
||||
let mut unauthorized = false;
|
||||
match conf.auth {
|
||||
|
@ -272,16 +271,7 @@ pub(crate) async fn tv_search(
|
|||
return status::Custom(Status::Unauthorized, RawXml("401 Unauthorized".to_string()));
|
||||
}
|
||||
|
||||
let search_parameters: SearchParameters = parameters.to_search_param("tv-search");
|
||||
|
||||
/*
|
||||
* return status::Custom(
|
||||
* Status::NotImplemented,
|
||||
* RawXml("501 Not Implemented: Search function not implemented".to_string()),
|
||||
* );
|
||||
*/
|
||||
|
||||
return search_handler(conf, search_parameters).await;
|
||||
return search_handler(conf, parameters).await;
|
||||
}
|
||||
|
||||
#[get("/api?t=movie&<form..>", rank = 4)]
|
||||
|
@ -291,7 +281,7 @@ pub(crate) async fn movie_search(
|
|||
form: SearchForm,
|
||||
) -> status::Custom<RawXml<String>> {
|
||||
// oh god this is horrible but it works
|
||||
let parameters = form.to_parameters((**conf).clone());
|
||||
let parameters = form.to_parameters((**conf).clone(), "movie-search");
|
||||
|
||||
let mut unauthorized = false;
|
||||
match conf.auth {
|
||||
|
@ -315,16 +305,7 @@ pub(crate) async fn movie_search(
|
|||
return status::Custom(Status::Unauthorized, RawXml("401 Unauthorized".to_string()));
|
||||
}
|
||||
|
||||
let search_parameters: SearchParameters = parameters.to_search_param("movie-search");
|
||||
|
||||
/*
|
||||
* return status::Custom(
|
||||
* Status::NotImplemented,
|
||||
* RawXml("501 Not Implemented: Search function not implemented".to_string()),
|
||||
* );
|
||||
*/
|
||||
|
||||
return search_handler(conf, search_parameters).await;
|
||||
return search_handler(conf, parameters).await;
|
||||
}
|
||||
|
||||
#[get("/api?t=music&<form..>", rank = 5)]
|
||||
|
@ -334,7 +315,7 @@ pub(crate) async fn music_search(
|
|||
form: SearchForm,
|
||||
) -> status::Custom<RawXml<String>> {
|
||||
// oh god this is horrible but it works
|
||||
let parameters = form.to_parameters((**conf).clone());
|
||||
let parameters = form.to_parameters((**conf).clone(), "audio-search");
|
||||
|
||||
let mut unauthorized = false;
|
||||
match conf.auth {
|
||||
|
@ -358,16 +339,7 @@ pub(crate) async fn music_search(
|
|||
return status::Custom(Status::Unauthorized, RawXml("401 Unauthorized".to_string()));
|
||||
}
|
||||
|
||||
let search_parameters: SearchParameters = parameters.to_search_param("audio-search");
|
||||
|
||||
/*
|
||||
* return status::Custom(
|
||||
* Status::NotImplemented,
|
||||
* RawXml("501 Not Implemented: Search function not implemented".to_string()),
|
||||
* );
|
||||
*/
|
||||
|
||||
return search_handler(conf, search_parameters).await;
|
||||
return search_handler(conf, parameters).await;
|
||||
}
|
||||
|
||||
#[get("/api?t=book&<form..>", rank = 6)]
|
||||
|
@ -377,7 +349,7 @@ pub(crate) async fn book_search(
|
|||
form: SearchForm,
|
||||
) -> status::Custom<RawXml<String>> {
|
||||
// oh god this is horrible but it works
|
||||
let parameters = form.to_parameters((**conf).clone());
|
||||
let parameters = form.to_parameters((**conf).clone(), "book-search");
|
||||
|
||||
let mut unauthorized = false;
|
||||
match conf.auth {
|
||||
|
@ -401,16 +373,7 @@ pub(crate) async fn book_search(
|
|||
return status::Custom(Status::Unauthorized, RawXml("401 Unauthorized".to_string()));
|
||||
}
|
||||
|
||||
let search_parameters: SearchParameters = parameters.to_search_param("book-search");
|
||||
|
||||
/*
|
||||
* return status::Custom(
|
||||
* Status::NotImplemented,
|
||||
* RawXml("501 Not Implemented: Search function not implemented".to_string()),
|
||||
* );
|
||||
*/
|
||||
|
||||
return search_handler(conf, search_parameters).await;
|
||||
return search_handler(conf, parameters).await;
|
||||
}
|
||||
|
||||
async fn search_handler(
|
||||
|
|
40
src/data.rs
40
src/data.rs
|
@ -122,45 +122,7 @@ pub struct Config {
|
|||
pub caps: Caps,
|
||||
}
|
||||
|
||||
/// An internal struct to hold the parameters for a search
|
||||
///
|
||||
/// Before being sent to the "client" program, it's turned into a SearchParameters object by `to_search_param()`, adding the search type
|
||||
#[derive(Debug, Clone, PartialEq, Eq, FromForm)]
|
||||
pub(crate) struct InternalSearchParameters {
|
||||
/// The text query for the search
|
||||
pub(crate) q: Option<String>,
|
||||
/// The apikey, for authentication
|
||||
pub(crate) apikey: Option<String>,
|
||||
/// A [`Vec`] containing the numeric category IDs to be included in the search results
|
||||
pub(crate) categories: Option<Vec<u32>>,
|
||||
/// A [`Vec`] containing the extended attribute names to be included in the search results
|
||||
pub(crate) attributes: Option<Vec<String>>,
|
||||
/// Whether *all* extended attributes should be included in the search results; overrules `attributes`
|
||||
pub(crate) extended_attrs: Option<bool>,
|
||||
/// How many items to skip/offset by in the results.
|
||||
pub(crate) offset: Option<u32>,
|
||||
/// The maximum number of items to return - also limited to whatever `limits` is in [`Caps`]
|
||||
pub(crate) limit: u32,
|
||||
}
|
||||
|
||||
impl InternalSearchParameters {
|
||||
/// Converts InternalSearchParameters to SearchParmaters, i.e. add `search_type`
|
||||
///
|
||||
/// Search types: `search`, `tv-search`, `movie-search`, `audio-search`, `book-search`
|
||||
pub(crate) fn to_search_param(&self, search_type: &str) -> SearchParameters {
|
||||
return SearchParameters {
|
||||
search_type: search_type.to_string(),
|
||||
q: self.q.clone(),
|
||||
apikey: self.apikey.clone(),
|
||||
categories: self.categories.clone(),
|
||||
attributes: self.attributes.clone(),
|
||||
extended_attrs: self.extended_attrs,
|
||||
offset: self.offset,
|
||||
limit: self.limit,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
/// Holds the parameters for a search query
|
||||
pub struct SearchParameters {
|
||||
/// What type of search this is
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
pub mod usage;
|
||||
pub mod implementation;
|
||||
pub mod usage;
|
||||
|
|
Loading…
Reference in a new issue