mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-05-14 01:45:46 +00:00
refactor(gui): refactor gui to use RemoteClient trait and RemoteManagement component (#1489)
* refactor(gui): refactor gui to use RemoteClient trait and RemoteManagement component * feat(gui): Add network config saving and refactor RemoteManagement
This commit is contained in:
@@ -51,6 +51,11 @@ struct ValidateConfigJsonReq {
|
||||
config: NetworkConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct SaveNetworkJsonReq {
|
||||
config: NetworkConfig,
|
||||
}
|
||||
|
||||
#[derive(Debug, serde::Deserialize, serde::Serialize)]
|
||||
struct RunNetworkJsonReq {
|
||||
config: NetworkConfig,
|
||||
@@ -177,9 +182,9 @@ impl NetworkApi {
|
||||
Path((machine_id, inst_id)): Path<(uuid::Uuid, uuid::Uuid)>,
|
||||
) -> Result<(), HttpHandleError> {
|
||||
client_mgr
|
||||
.handle_remove_network_instance(
|
||||
.handle_remove_network_instances(
|
||||
(Self::get_user_id(&auth_session)?, machine_id),
|
||||
inst_id,
|
||||
vec![inst_id],
|
||||
)
|
||||
.await
|
||||
.map_err(convert_error)
|
||||
@@ -232,6 +237,28 @@ impl NetworkApi {
|
||||
.map_err(convert_error)
|
||||
}
|
||||
|
||||
async fn handle_save_network_config(
|
||||
auth_session: AuthSession,
|
||||
State(client_mgr): AppState,
|
||||
Path((machine_id, inst_id)): Path<(uuid::Uuid, uuid::Uuid)>,
|
||||
Json(payload): Json<SaveNetworkJsonReq>,
|
||||
) -> Result<(), HttpHandleError> {
|
||||
if payload.config.instance_id() != inst_id.to_string() {
|
||||
return Err((
|
||||
StatusCode::BAD_REQUEST,
|
||||
other_error("Instance ID mismatch".to_string()).into(),
|
||||
));
|
||||
}
|
||||
client_mgr
|
||||
.handle_save_network_config(
|
||||
(Self::get_user_id(&auth_session)?, machine_id),
|
||||
inst_id,
|
||||
payload.config,
|
||||
)
|
||||
.await
|
||||
.map_err(convert_error)
|
||||
}
|
||||
|
||||
async fn handle_get_network_config(
|
||||
auth_session: AuthSession,
|
||||
State(client_mgr): AppState,
|
||||
@@ -269,7 +296,7 @@ impl NetworkApi {
|
||||
)
|
||||
.route(
|
||||
"/api/v1/machines/:machine-id/networks/config/:inst-id",
|
||||
get(Self::handle_get_network_config),
|
||||
get(Self::handle_get_network_config).put(Self::handle_save_network_config),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user