mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-06-14 11:42:02 +08:00
feat: 支持在线升级功能
This commit is contained in:
@@ -24,8 +24,8 @@ mod audio;
|
||||
mod auth;
|
||||
mod hid;
|
||||
mod msd;
|
||||
mod rustdesk;
|
||||
mod rtsp;
|
||||
mod rustdesk;
|
||||
mod stream;
|
||||
pub(crate) mod video;
|
||||
mod web;
|
||||
@@ -36,11 +36,11 @@ 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 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,
|
||||
regenerate_device_password, update_rustdesk_config,
|
||||
};
|
||||
pub use rtsp::{get_rtsp_config, get_rtsp_status, update_rtsp_config};
|
||||
pub use stream::{get_stream_config, update_stream_config};
|
||||
pub use video::{get_video_config, update_video_config};
|
||||
pub use web::{get_web_config, update_web_config};
|
||||
|
||||
@@ -54,7 +54,10 @@ pub async fn update_rtsp_config(
|
||||
})
|
||||
.await
|
||||
{
|
||||
tracing::error!("Failed to rollback RTSP config after apply failure: {}", rollback_err);
|
||||
tracing::error!(
|
||||
"Failed to rollback RTSP config after apply failure: {}",
|
||||
rollback_err
|
||||
);
|
||||
return Err(AppError::ServiceUnavailable(format!(
|
||||
"RTSP apply failed: {}; rollback failed: {}",
|
||||
err, rollback_err
|
||||
|
||||
@@ -14,6 +14,7 @@ use crate::config::{AppConfig, StreamMode};
|
||||
use crate::error::{AppError, Result};
|
||||
use crate::events::SystemEvent;
|
||||
use crate::state::AppState;
|
||||
use crate::update::{UpdateChannel, UpdateOverviewResponse, UpdateStatusResponse, UpgradeRequest};
|
||||
use crate::video::codec_constraints::codec_to_id;
|
||||
use crate::video::encoder::BitratePreset;
|
||||
|
||||
@@ -751,7 +752,8 @@ pub async fn setup_init(
|
||||
// Start RTSP if enabled
|
||||
if new_config.rtsp.enabled {
|
||||
let empty_config = crate::config::RtspConfig::default();
|
||||
if let Err(e) = config::apply::apply_rtsp_config(&state, &empty_config, &new_config.rtsp).await
|
||||
if let Err(e) =
|
||||
config::apply::apply_rtsp_config(&state, &empty_config, &new_config.rtsp).await
|
||||
{
|
||||
tracing::warn!("Failed to start RTSP during setup: {}", e);
|
||||
} else {
|
||||
@@ -1641,7 +1643,10 @@ pub async fn stream_constraints_get(
|
||||
.into_iter()
|
||||
.map(str::to_string)
|
||||
.collect(),
|
||||
locked_codec: constraints.locked_codec.map(codec_to_id).map(str::to_string),
|
||||
locked_codec: constraints
|
||||
.locked_codec
|
||||
.map(codec_to_id)
|
||||
.map(str::to_string),
|
||||
disallow_mjpeg: !constraints.allow_mjpeg,
|
||||
sources: ConstraintSources {
|
||||
rustdesk: constraints.rustdesk_enabled,
|
||||
@@ -1929,7 +1934,9 @@ pub async fn mjpeg_stream(
|
||||
continue;
|
||||
};
|
||||
|
||||
if frame.is_valid_jpeg() && tx.send(create_mjpeg_part(frame.data())).await.is_err() {
|
||||
if frame.is_valid_jpeg()
|
||||
&& tx.send(create_mjpeg_part(frame.data())).await.is_err()
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -3130,3 +3137,37 @@ pub async fn system_restart(State(state): State<Arc<AppState>>) -> Json<LoginRes
|
||||
message: Some("Restarting...".to_string()),
|
||||
})
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Online Update
|
||||
// ============================================================================
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateOverviewQuery {
|
||||
pub channel: Option<UpdateChannel>,
|
||||
}
|
||||
|
||||
pub async fn update_overview(
|
||||
State(state): State<Arc<AppState>>,
|
||||
axum::extract::Query(query): axum::extract::Query<UpdateOverviewQuery>,
|
||||
) -> Result<Json<UpdateOverviewResponse>> {
|
||||
let channel = query.channel.unwrap_or(UpdateChannel::Stable);
|
||||
let response = state.update.overview(channel).await?;
|
||||
Ok(Json(response))
|
||||
}
|
||||
|
||||
pub async fn update_upgrade(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Json(req): Json<UpgradeRequest>,
|
||||
) -> Result<Json<LoginResponse>> {
|
||||
state.update.start_upgrade(req, state.shutdown_tx.clone())?;
|
||||
|
||||
Ok(Json(LoginResponse {
|
||||
success: true,
|
||||
message: Some("Upgrade started".to_string()),
|
||||
}))
|
||||
}
|
||||
|
||||
pub async fn update_status(State(state): State<Arc<AppState>>) -> Json<UpdateStatusResponse> {
|
||||
Json(state.update.status().await)
|
||||
}
|
||||
|
||||
@@ -136,6 +136,9 @@ pub fn create_router(state: Arc<AppState>) -> Router {
|
||||
.route("/config/auth", patch(handlers::config::update_auth_config))
|
||||
// System control
|
||||
.route("/system/restart", post(handlers::system_restart))
|
||||
.route("/update/overview", get(handlers::update_overview))
|
||||
.route("/update/upgrade", post(handlers::update_upgrade))
|
||||
.route("/update/status", get(handlers::update_status))
|
||||
// MSD (Mass Storage Device) endpoints
|
||||
.route("/msd/status", get(handlers::msd_status))
|
||||
.route("/msd/images", get(handlers::msd_images_list))
|
||||
|
||||
Reference in New Issue
Block a user