mirror of
https://codeberg.org/YGGverse/psocks.git
synced 2026-03-31 08:25:27 +00:00
fix status change result
This commit is contained in:
parent
abeeae2f16
commit
7a440231a0
2 changed files with 7 additions and 6 deletions
10
src/main.rs
10
src/main.rs
|
|
@ -32,16 +32,18 @@ async fn api_totals(totals: &State<Arc<Total>>, startup_time: &State<Instant>) -
|
|||
async fn api_list_enable(
|
||||
alias: &str,
|
||||
rules: &State<Arc<RwLock<Rules>>>,
|
||||
) -> Result<Json<bool>, Status> {
|
||||
Ok(Json(rules.write().await.set_status(alias, true)))
|
||||
) -> Result<Json<Option<bool>>, Status> {
|
||||
Ok(Json(
|
||||
rules.write().await.set_status(alias, true).map(|old| !old),
|
||||
))
|
||||
}
|
||||
|
||||
#[rocket::get("/api/list/disable/<alias>")]
|
||||
async fn api_list_disable(
|
||||
alias: &str,
|
||||
rules: &State<Arc<RwLock<Rules>>>,
|
||||
) -> Result<Json<bool>, Status> {
|
||||
Ok(Json(!rules.write().await.set_status(alias, false)))
|
||||
) -> Result<Json<Option<bool>>, Status> {
|
||||
Ok(Json(rules.write().await.set_status(alias, false)))
|
||||
}
|
||||
|
||||
#[rocket::launch]
|
||||
|
|
|
|||
|
|
@ -17,11 +17,10 @@ impl Rules {
|
|||
.is_none())
|
||||
}
|
||||
/// 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
|
||||
.get_mut(list_alias)
|
||||
.map(|list| list.set_status(status))
|
||||
.is_some()
|
||||
}
|
||||
/// Check if rule is exist in the index
|
||||
pub fn any(&self, value: &str) -> bool {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue