fix status change result

This commit is contained in:
yggverse 2026-03-28 04:56:00 +02:00
parent abeeae2f16
commit 7a440231a0
2 changed files with 7 additions and 6 deletions

View file

@ -32,16 +32,18 @@ async fn api_totals(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -
async fn api_list_enable( async fn api_list_enable(
alias: &str, alias: &str,
rules: &State<Arc<RwLock<Rules>>>, rules: &State<Arc<RwLock<Rules>>>,
) -> Result<Json<bool>, Status> { ) -> Result<Json<Option<bool>>, Status> {
Ok(Json(rules.write().await.set_status(alias, true))) Ok(Json(
rules.write().await.set_status(alias, true).map(|old| !old),
))
} }
#[rocket::get("/api/list/disable/<alias>")] #[rocket::get("/api/list/disable/<alias>")]
async fn api_list_disable( async fn api_list_disable(
alias: &str, alias: &str,
rules: &State<Arc<RwLock<Rules>>>, rules: &State<Arc<RwLock<Rules>>>,
) -> Result<Json<bool>, Status> { ) -> Result<Json<Option<bool>>, Status> {
Ok(Json(!rules.write().await.set_status(alias, false))) Ok(Json(rules.write().await.set_status(alias, false)))
} }
#[rocket::launch] #[rocket::launch]

View file

@ -17,11 +17,10 @@ impl Rules {
.is_none()) .is_none())
} }
/// Change rule set status by list ID /// Change rule set status by list ID
pub fn set_status(&mut self, list_alias: &str, status: bool) -> bool { pub fn set_status(&mut self, list_alias: &str, status: bool) -> Option<bool> {
self.0 self.0
.get_mut(list_alias) .get_mut(list_alias)
.map(|list| list.set_status(status)) .map(|list| list.set_status(status))
.is_some()
} }
/// Check if rule is exist in the index /// Check if rule is exist in the index
pub fn any(&self, value: &str) -> bool { pub fn any(&self, value: &str) -> bool {