mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-06-18 01:01:44 +08:00
refactor: 删除部分多余的代码和注释
This commit is contained in:
@@ -1,5 +1,3 @@
|
||||
//! RustDesk 配置 Handler
|
||||
|
||||
use axum::{extract::State, Json};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -10,18 +8,14 @@ use crate::state::AppState;
|
||||
use super::apply::apply_rustdesk_config;
|
||||
use super::types::RustDeskConfigUpdate;
|
||||
|
||||
/// RustDesk 配置响应(隐藏敏感信息)
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct RustDeskConfigResponse {
|
||||
pub enabled: bool,
|
||||
pub rendezvous_server: String,
|
||||
pub relay_server: Option<String>,
|
||||
pub device_id: String,
|
||||
/// 是否已设置密码
|
||||
pub has_password: bool,
|
||||
/// 是否已设置密钥对
|
||||
pub has_keypair: bool,
|
||||
/// 是否已设置 relay key
|
||||
pub has_relay_key: bool,
|
||||
}
|
||||
|
||||
@@ -39,7 +33,6 @@ impl From<&RustDeskConfig> for RustDeskConfigResponse {
|
||||
}
|
||||
}
|
||||
|
||||
/// RustDesk 状态响应
|
||||
#[derive(Debug, serde::Serialize)]
|
||||
pub struct RustDeskStatusResponse {
|
||||
pub config: RustDeskConfigResponse,
|
||||
@@ -47,20 +40,17 @@ pub struct RustDeskStatusResponse {
|
||||
pub rendezvous_status: Option<String>,
|
||||
}
|
||||
|
||||
/// 获取 RustDesk 配置
|
||||
pub async fn get_rustdesk_config(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Json<RustDeskConfigResponse> {
|
||||
Json(RustDeskConfigResponse::from(&state.config.get().rustdesk))
|
||||
}
|
||||
|
||||
/// 获取 RustDesk 完整状态(配置 + 服务状态)
|
||||
pub async fn get_rustdesk_status(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Json<RustDeskStatusResponse> {
|
||||
let config = state.config.get().rustdesk.clone();
|
||||
|
||||
// 获取服务状态
|
||||
let (service_status, rendezvous_status) = {
|
||||
let guard = state.rustdesk.read().await;
|
||||
if let Some(ref service) = *guard {
|
||||
@@ -79,18 +69,14 @@ pub async fn get_rustdesk_status(
|
||||
})
|
||||
}
|
||||
|
||||
/// 更新 RustDesk 配置
|
||||
pub async fn update_rustdesk_config(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Json(req): Json<RustDeskConfigUpdate>,
|
||||
) -> Result<Json<RustDeskConfigResponse>> {
|
||||
// 1. 验证请求
|
||||
req.validate()?;
|
||||
|
||||
// 2. 获取旧配置
|
||||
let old_config = state.config.get().rustdesk.clone();
|
||||
|
||||
// 3. 应用更新到配置存储
|
||||
state
|
||||
.config
|
||||
.update(|config| {
|
||||
@@ -98,15 +84,12 @@ pub async fn update_rustdesk_config(
|
||||
})
|
||||
.await?;
|
||||
|
||||
// 4. 获取新配置
|
||||
let new_config = state.config.get().rustdesk.clone();
|
||||
|
||||
// 5. 应用到子系统(热重载)
|
||||
if let Err(e) = apply_rustdesk_config(&state, &old_config, &new_config).await {
|
||||
tracing::error!("Failed to apply RustDesk config: {}", e);
|
||||
}
|
||||
|
||||
// Share a non-sensitive summary for frontend UX
|
||||
let constraints = state.stream_manager.codec_constraints().await;
|
||||
if constraints.rustdesk_enabled || constraints.rtsp_enabled {
|
||||
tracing::info!(
|
||||
@@ -118,7 +101,6 @@ pub async fn update_rustdesk_config(
|
||||
Ok(Json(RustDeskConfigResponse::from(&new_config)))
|
||||
}
|
||||
|
||||
/// 重新生成设备 ID
|
||||
pub async fn regenerate_device_id(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Result<Json<RustDeskConfigResponse>> {
|
||||
@@ -133,7 +115,6 @@ pub async fn regenerate_device_id(
|
||||
Ok(Json(RustDeskConfigResponse::from(&new_config)))
|
||||
}
|
||||
|
||||
/// 重新生成设备密码
|
||||
pub async fn regenerate_device_password(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Result<Json<RustDeskConfigResponse>> {
|
||||
@@ -148,7 +129,6 @@ pub async fn regenerate_device_password(
|
||||
Ok(Json(RustDeskConfigResponse::from(&new_config)))
|
||||
}
|
||||
|
||||
/// 获取设备密码(已认证用户)
|
||||
pub async fn get_device_password(State(state): State<Arc<AppState>>) -> Json<serde_json::Value> {
|
||||
let config = state.config.get().rustdesk.clone();
|
||||
Json(serde_json::json!({
|
||||
|
||||
Reference in New Issue
Block a user