feat: 实现 Redfish API 标准接口;支持通过前端开关控制 Redfish 服务

This commit is contained in:
Fucheng Sha
2026-05-12 10:45:42 +08:00
parent 17cd74f64c
commit 4e8c342905
23 changed files with 2170 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ mod audio;
mod auth;
mod hid;
mod msd;
mod redfish;
mod rtsp;
mod rustdesk;
mod stream;
@@ -17,6 +18,7 @@ pub use audio::{get_audio_config, update_audio_config};
pub use auth::{get_auth_config, update_auth_config};
pub use hid::{get_hid_config, update_hid_config};
pub use msd::{get_msd_config, update_msd_config};
pub use redfish::{get_redfish_config, update_redfish_config};
pub use rtsp::{get_rtsp_config, get_rtsp_status, update_rtsp_config};
pub use rustdesk::{
get_device_password, get_rustdesk_config, get_rustdesk_status, regenerate_device_id,

View File

@@ -0,0 +1,29 @@
use axum::{extract::State, Json};
use std::sync::Arc;
use crate::error::Result;
use crate::state::AppState;
use super::types::{RedfishConfigResponse, RedfishConfigUpdate};
pub async fn get_redfish_config(State(state): State<Arc<AppState>>) -> Json<RedfishConfigResponse> {
Json(RedfishConfigResponse {
enabled: state.config.get().redfish.enabled,
})
}
pub async fn update_redfish_config(
State(state): State<Arc<AppState>>,
Json(req): Json<RedfishConfigUpdate>,
) -> Result<Json<RedfishConfigResponse>> {
state
.config
.update(|config| {
req.apply_to(&mut config.redfish);
})
.await?;
Ok(Json(RedfishConfigResponse {
enabled: state.config.get().redfish.enabled,
}))
}

View File

@@ -1009,6 +1009,24 @@ impl WebConfigUpdate {
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RedfishConfigResponse {
pub enabled: bool,
}
#[derive(Debug, Deserialize)]
pub struct RedfishConfigUpdate {
pub enabled: Option<bool>,
}
impl RedfishConfigUpdate {
pub fn apply_to(&self, config: &mut crate::config::RedfishConfig) {
if let Some(enabled) = self.enabled {
config.enabled = enabled;
}
}
}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -18,6 +18,15 @@ use crate::hid::websocket::ws_hid_handler;
use crate::state::AppState;
pub fn create_router(state: Arc<AppState>) -> Router {
let redfish_router = {
let config = state.config.get();
if config.redfish.enabled {
Some(crate::redfish::routes::create_redfish_router(state.clone()))
} else {
None
}
};
let cors = CorsLayer::new()
.allow_origin(Any)
.allow_methods(Any)
@@ -137,6 +146,9 @@ pub fn create_router(state: Arc<AppState>) -> Router {
// Auth configuration
.route("/config/auth", get(handlers::config::get_auth_config))
.route("/config/auth", patch(handlers::config::update_auth_config))
// Redfish configuration
.route("/config/redfish", get(handlers::config::get_redfish_config))
.route("/config/redfish", patch(handlers::config::update_redfish_config))
// System control
.route("/system/restart", post(handlers::system_restart))
.route("/update/overview", get(handlers::update_overview))
@@ -245,10 +257,15 @@ pub fn create_router(state: Arc<AppState>) -> Router {
let static_routes = super::static_files::static_file_router();
// Main router
Router::new()
let main_router = Router::new()
.nest("/api", api_routes)
.merge(static_routes)
.layer(TraceLayer::new_for_http())
.layer(cors)
.with_state(state)
.with_state(state);
match redfish_router {
Some(rf) => main_router.merge(rf),
None => main_router,
}
}