Skip to content

Commit

Permalink
fix: tun api
Browse files Browse the repository at this point in the history
  • Loading branch information
XOR-op committed Mar 25, 2023
1 parent 85a3a33 commit 53f72e1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
6 changes: 6 additions & 0 deletions boltapi/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ pub struct TrafficResp {
pub upload_speed: Option<u64>,
pub download_speed: Option<u64>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(deny_unknown_fields)]
pub struct TunStatusSchema {
pub enabled: bool,
}
20 changes: 9 additions & 11 deletions boltconn/src/external/api_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use axum::routing::{delete, get, post};
use axum::{Json, Router};
use boltapi::{
GetEavesdropDataResp, GetEavesdropRangeReq, GetGroupRespSchema, ProxyData, SetGroupReqSchema,
TrafficResp,
TrafficResp, TunStatusSchema,
};
use serde_json::json;
use std::collections::HashMap;
Expand Down Expand Up @@ -117,22 +117,20 @@ impl ApiServer {
}

async fn get_tun_configure(State(server): State<Self>) -> Json<serde_json::Value> {
Json(json!(server.tun_configure.lock().unwrap().get_status()))
Json(json!(TunStatusSchema {
enabled: server.tun_configure.lock().unwrap().get_status()
}))
}

async fn set_tun_configure(
State(server): State<Self>,
Json(flag): Json<serde_json::Value>,
Json(status): Json<TunStatusSchema>,
) -> Json<serde_json::Value> {
Json(json!(if let Some(flag) = flag.as_bool() {
if flag {
server.tun_configure.lock().unwrap().enable().is_ok()
} else {
server.tun_configure.lock().unwrap().disable();
true
}
Json(json!(if status.enabled {
server.tun_configure.lock().unwrap().enable().is_ok()
} else {
false
server.tun_configure.lock().unwrap().disable();
true
}))
}

Expand Down

0 comments on commit 53f72e1

Please sign in to comment.