fix CONFIG == None not working

This commit is contained in:
askiiart 2024-11-25 10:20:29 -06:00
parent 52a8c48825
commit 1beab57613
Signed by untrusted user who does not match committer: askiiart
GPG key ID: EA85979611654C30

View file

@ -7,7 +7,6 @@ use rocket::http::Status;
use rocket::response::status; use rocket::response::status;
use xml::writer::{EmitterConfig, XmlEvent}; use xml::writer::{EmitterConfig, XmlEvent};
/// Holds the config for torznab-toolkit. /// Holds the config for torznab-toolkit.
/// ///
/// A search function (`/api?t=search`) and capabilities (`/api?t=caps` - `Caps`) are required, everything else is optional. /// A search function (`/api?t=search`) and capabilities (`/api?t=caps` - `Caps`) are required, everything else is optional.
@ -23,12 +22,15 @@ pub static mut CONFIG: Option<Config> = None;
#[get("/api?t=caps")] #[get("/api?t=caps")]
pub(crate) fn caps() -> status::Custom<String> { pub(crate) fn caps() -> status::Custom<String> {
unsafe { unsafe {
if CONFIG == None { match CONFIG {
None => {
return status::Custom( return status::Custom(
Status::InternalServerError, Status::InternalServerError,
"500 Internal server error: Config not specified".to_string(), "500 Internal server error: Config not specified".to_string(),
); );
} }
Some(_) => {}
}
} }
let output = stdout(); let output = stdout();
@ -121,7 +123,7 @@ mod tests {
CONFIG = Some(create_config()); CONFIG = Some(create_config());
println!("{:?}", CONFIG); println!("{:?}", CONFIG);
} }
caps(); println!("{:?}", caps());
} }
#[test] #[test]
@ -129,6 +131,6 @@ mod tests {
unsafe { unsafe {
println!("{:?}", CONFIG); println!("{:?}", CONFIG);
} }
caps(); println!("{:?}", caps());
} }
} }