From f2b559ab5f29c749de40330620129aa6c38d74b9 Mon Sep 17 00:00:00 2001 From: askiiart Date: Sun, 1 Dec 2024 18:51:35 -0600 Subject: [PATCH] async it --- README.md | 2 +- src/api.rs | 24 ++++++++++++------------ src/dummy.rs | 12 ++++++------ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 61b96eb..f97af52 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 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 diff --git a/src/api.rs b/src/api.rs index 2c8011e..216917f 100644 --- a/src/api.rs +++ b/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. #[get("/api?t=caps")] -pub(crate) fn caps() -> status::Custom> { +pub(crate) async fn caps() -> status::Custom> { // 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 let conf; @@ -235,7 +235,7 @@ pub(crate) fn caps() -> status::Custom> { #[get("/api?t=search&")] /// The general search function -pub(crate) fn search(form: SearchForm) -> status::Custom> { +pub(crate) async fn search(form: SearchForm) -> status::Custom> { // 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 let conf; @@ -273,12 +273,12 @@ pub(crate) fn search(form: SearchForm) -> status::Custom> { 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&")] /// The TV search function -pub(crate) fn tv_search(form: SearchForm) -> status::Custom> { +pub(crate) async fn tv_search(form: SearchForm) -> status::Custom> { // 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 let conf; @@ -323,12 +323,12 @@ pub(crate) fn tv_search(form: SearchForm) -> status::Custom> { * ); */ - return search_handler(conf, search_parameters); + return search_handler(conf, search_parameters).await; } #[get("/api?t=movie&")] /// The movie search function -pub(crate) fn movie_search(form: SearchForm) -> status::Custom> { +pub(crate) async fn movie_search(form: SearchForm) -> status::Custom> { // 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 let conf; @@ -373,12 +373,12 @@ pub(crate) fn movie_search(form: SearchForm) -> status::Custom> { * ); */ - return search_handler(conf, search_parameters); + return search_handler(conf, search_parameters).await; } #[get("/api?t=music&")] /// The music search function -pub(crate) fn music_search(form: SearchForm) -> status::Custom> { +pub(crate) async fn music_search(form: SearchForm) -> status::Custom> { // 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 let conf; @@ -423,12 +423,12 @@ pub(crate) fn music_search(form: SearchForm) -> status::Custom> { * ); */ - return search_handler(conf, search_parameters); + return search_handler(conf, search_parameters).await; } #[get("/api?t=book&")] /// The music search function -pub(crate) fn book_search(form: SearchForm) -> status::Custom> { +pub(crate) async fn book_search(form: SearchForm) -> status::Custom> { // 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 let conf; @@ -473,10 +473,10 @@ pub(crate) fn book_search(form: SearchForm) -> status::Custom> { * ); */ - return search_handler(conf, search_parameters); + return search_handler(conf, search_parameters).await; } -fn search_handler(conf: Config, parameters: SearchParameters) -> status::Custom> { +async fn search_handler(conf: Config, parameters: SearchParameters) -> status::Custom> { let buffer = Vec::new(); let mut writer = EmitterConfig::new().create_writer(buffer); writer diff --git a/src/dummy.rs b/src/dummy.rs index e599035..2d704af 100644 --- a/src/dummy.rs +++ b/src/dummy.rs @@ -91,21 +91,21 @@ pub(crate) fn create_empty_config() -> Config { mod tests { use crate::{api, dummy::create_empty_config, run}; - #[test] - fn caps_test_with_empty_config() { + #[actix_rt::test] + async fn caps_test_with_empty_config() { unsafe { crate::api::CONFIG = Some(create_empty_config()); println!("{:?}", crate::api::CONFIG); } - println!("{:?}", crate::api::caps()); + println!("{:?}", crate::api::caps().await); } - #[test] - fn caps_test_no_config() { + #[actix_rt::test] + async fn caps_test_no_config() { unsafe { println!("{:?}", crate::api::CONFIG); } - println!("{:?}", crate::api::caps()); + println!("{:?}", crate::api::caps().await); } #[actix_rt::test]