async it
This commit is contained in:
parent
546e4944b4
commit
f2b559ab5f
3 changed files with 19 additions and 19 deletions
|
@ -1,6 +1,6 @@
|
||||||
# Torznab Toolkit
|
# Torznab Toolkit
|
||||||
|
|
||||||
A safe, multi-threaded toolkit for adding Torznab APIs to programs. You just focus on the indexer itself, we abstract away the hell that is the Torznab API.
|
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, and torznab-toolkit will run the API for you
|
||||||
|
|
||||||
|
|
24
src/api.rs
24
src/api.rs
|
@ -101,7 +101,7 @@ lazy_static! {
|
||||||
///
|
///
|
||||||
/// Note that an apikey is *not* required for this function, regardless of whether it's required for the rest.
|
/// Note that an apikey is *not* required for this function, regardless of whether it's required for the rest.
|
||||||
#[get("/api?t=caps")]
|
#[get("/api?t=caps")]
|
||||||
pub(crate) fn caps() -> status::Custom<RawXml<String>> {
|
pub(crate) async fn caps() -> status::Custom<RawXml<String>> {
|
||||||
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
||||||
// So this is needed
|
// So this is needed
|
||||||
let conf;
|
let conf;
|
||||||
|
@ -235,7 +235,7 @@ pub(crate) fn caps() -> status::Custom<RawXml<String>> {
|
||||||
|
|
||||||
#[get("/api?t=search&<form..>")]
|
#[get("/api?t=search&<form..>")]
|
||||||
/// The general search function
|
/// The general search function
|
||||||
pub(crate) fn search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
pub(crate) async fn search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
||||||
// So this is needed
|
// So this is needed
|
||||||
let conf;
|
let conf;
|
||||||
|
@ -273,12 +273,12 @@ pub(crate) fn search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
|
|
||||||
let search_parameters: SearchParameters = parameters.to_search_param("search");
|
let search_parameters: SearchParameters = parameters.to_search_param("search");
|
||||||
|
|
||||||
return search_handler(conf, search_parameters);
|
return search_handler(conf, search_parameters).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/api?t=tvsearch&<form..>")]
|
#[get("/api?t=tvsearch&<form..>")]
|
||||||
/// The TV search function
|
/// The TV search function
|
||||||
pub(crate) fn tv_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
pub(crate) async fn tv_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
||||||
// So this is needed
|
// So this is needed
|
||||||
let conf;
|
let conf;
|
||||||
|
@ -323,12 +323,12 @@ pub(crate) fn tv_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
* );
|
* );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return search_handler(conf, search_parameters);
|
return search_handler(conf, search_parameters).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/api?t=movie&<form..>")]
|
#[get("/api?t=movie&<form..>")]
|
||||||
/// The movie search function
|
/// The movie search function
|
||||||
pub(crate) fn movie_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
pub(crate) async fn movie_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
||||||
// So this is needed
|
// So this is needed
|
||||||
let conf;
|
let conf;
|
||||||
|
@ -373,12 +373,12 @@ pub(crate) fn movie_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
* );
|
* );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return search_handler(conf, search_parameters);
|
return search_handler(conf, search_parameters).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/api?t=music&<form..>")]
|
#[get("/api?t=music&<form..>")]
|
||||||
/// The music search function
|
/// The music search function
|
||||||
pub(crate) fn music_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
pub(crate) async fn music_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
||||||
// So this is needed
|
// So this is needed
|
||||||
let conf;
|
let conf;
|
||||||
|
@ -423,12 +423,12 @@ pub(crate) fn music_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
* );
|
* );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return search_handler(conf, search_parameters);
|
return search_handler(conf, search_parameters).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[get("/api?t=book&<form..>")]
|
#[get("/api?t=book&<form..>")]
|
||||||
/// The music search function
|
/// The music search function
|
||||||
pub(crate) fn book_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
pub(crate) async fn book_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
// The compiler won't let you get a field from a struct in the Option here, since the default is None
|
||||||
// So this is needed
|
// So this is needed
|
||||||
let conf;
|
let conf;
|
||||||
|
@ -473,10 +473,10 @@ pub(crate) fn book_search(form: SearchForm) -> status::Custom<RawXml<String>> {
|
||||||
* );
|
* );
|
||||||
*/
|
*/
|
||||||
|
|
||||||
return search_handler(conf, search_parameters);
|
return search_handler(conf, search_parameters).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search_handler(conf: Config, parameters: SearchParameters) -> status::Custom<RawXml<String>> {
|
async fn search_handler(conf: Config, parameters: SearchParameters) -> status::Custom<RawXml<String>> {
|
||||||
let buffer = Vec::new();
|
let buffer = Vec::new();
|
||||||
let mut writer = EmitterConfig::new().create_writer(buffer);
|
let mut writer = EmitterConfig::new().create_writer(buffer);
|
||||||
writer
|
writer
|
||||||
|
|
12
src/dummy.rs
12
src/dummy.rs
|
@ -91,21 +91,21 @@ pub(crate) fn create_empty_config() -> Config {
|
||||||
mod tests {
|
mod tests {
|
||||||
use crate::{api, dummy::create_empty_config, run};
|
use crate::{api, dummy::create_empty_config, run};
|
||||||
|
|
||||||
#[test]
|
#[actix_rt::test]
|
||||||
fn caps_test_with_empty_config() {
|
async fn caps_test_with_empty_config() {
|
||||||
unsafe {
|
unsafe {
|
||||||
crate::api::CONFIG = Some(create_empty_config());
|
crate::api::CONFIG = Some(create_empty_config());
|
||||||
println!("{:?}", crate::api::CONFIG);
|
println!("{:?}", crate::api::CONFIG);
|
||||||
}
|
}
|
||||||
println!("{:?}", crate::api::caps());
|
println!("{:?}", crate::api::caps().await);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[actix_rt::test]
|
||||||
fn caps_test_no_config() {
|
async fn caps_test_no_config() {
|
||||||
unsafe {
|
unsafe {
|
||||||
println!("{:?}", crate::api::CONFIG);
|
println!("{:?}", crate::api::CONFIG);
|
||||||
}
|
}
|
||||||
println!("{:?}", crate::api::caps());
|
println!("{:?}", crate::api::caps().await);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[actix_rt::test]
|
#[actix_rt::test]
|
||||||
|
|
Loading…
Reference in a new issue