mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-07-29 15:31:46 +08:00
Merge commit '4b7be20fe0cce3e7979cc3bdfdd7b02ec6630c00' into dev
This commit is contained in:
64
src/web/handlers/computer_use.rs
Normal file
64
src/web/handlers/computer_use.rs
Normal file
@@ -0,0 +1,64 @@
|
||||
use axum::{
|
||||
extract::{ws::WebSocketUpgrade, Query, State},
|
||||
response::Response,
|
||||
Json,
|
||||
};
|
||||
use serde::Deserialize;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::computer_use::{
|
||||
ComputerUseConfigResponse, ComputerUseConfigUpdate, ComputerUseSessionSummary,
|
||||
ComputerUseStartRequest,
|
||||
};
|
||||
use crate::error::Result;
|
||||
use crate::state::AppState;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct ComputerUseWsQuery {
|
||||
client_id: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn computer_use_config(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Json<ComputerUseConfigResponse> {
|
||||
Json(state.computer_use.config_response())
|
||||
}
|
||||
|
||||
pub async fn computer_use_update_config(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Json(req): Json<ComputerUseConfigUpdate>,
|
||||
) -> Result<Json<ComputerUseConfigResponse>> {
|
||||
Ok(Json(state.computer_use.update_config(req).await?))
|
||||
}
|
||||
|
||||
pub async fn computer_use_session(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Json<ComputerUseSessionSummary> {
|
||||
Json(state.computer_use.summary().await)
|
||||
}
|
||||
|
||||
pub async fn computer_use_start(
|
||||
State(state): State<Arc<AppState>>,
|
||||
Json(req): Json<ComputerUseStartRequest>,
|
||||
) -> Result<Json<ComputerUseSessionSummary>> {
|
||||
Ok(Json(state.computer_use.start(req).await?))
|
||||
}
|
||||
|
||||
pub async fn computer_use_stop(
|
||||
State(state): State<Arc<AppState>>,
|
||||
) -> Result<Json<ComputerUseSessionSummary>> {
|
||||
Ok(Json(state.computer_use.stop().await?))
|
||||
}
|
||||
|
||||
pub async fn computer_use_ws(
|
||||
ws: WebSocketUpgrade,
|
||||
State(state): State<Arc<AppState>>,
|
||||
Query(query): Query<ComputerUseWsQuery>,
|
||||
) -> Response {
|
||||
ws.on_upgrade(move |socket| {
|
||||
state
|
||||
.computer_use
|
||||
.clone()
|
||||
.handle_socket(socket, query.client_id)
|
||||
})
|
||||
}
|
||||
@@ -47,6 +47,7 @@ fn sanitize_config_for_api(config: &mut AppConfig) {
|
||||
config.auth.totp_secret = None;
|
||||
|
||||
config.stream.turn_password = None;
|
||||
config.computer_use.openai_api_key = None;
|
||||
|
||||
config.rustdesk.device_password.clear();
|
||||
config.rustdesk.relay_key = None;
|
||||
|
||||
@@ -7,6 +7,7 @@ mod account;
|
||||
mod atx_api;
|
||||
mod audio_api;
|
||||
mod auth;
|
||||
mod computer_use;
|
||||
mod hid_api;
|
||||
mod inventory;
|
||||
#[cfg(unix)]
|
||||
@@ -21,6 +22,7 @@ pub use account::*;
|
||||
pub use atx_api::*;
|
||||
pub use audio_api::*;
|
||||
pub use auth::*;
|
||||
pub use computer_use::*;
|
||||
pub use hid_api::*;
|
||||
pub use inventory::*;
|
||||
#[cfg(unix)]
|
||||
|
||||
@@ -170,6 +170,18 @@ pub fn create_router(state: Arc<AppState>) -> Router {
|
||||
// Web server configuration
|
||||
.route("/config/web", get(handlers::config::get_web_config))
|
||||
.route("/config/web", patch(handlers::config::update_web_config))
|
||||
.route("/config/computer-use", get(handlers::computer_use_config))
|
||||
.route(
|
||||
"/config/computer-use",
|
||||
patch(handlers::computer_use_update_config),
|
||||
)
|
||||
.route("/computer-use/session", get(handlers::computer_use_session))
|
||||
.route("/computer-use/session", post(handlers::computer_use_start))
|
||||
.route(
|
||||
"/computer-use/session/stop",
|
||||
post(handlers::computer_use_stop),
|
||||
)
|
||||
.route("/ws/computer-use", any(handlers::computer_use_ws))
|
||||
// Auth configuration
|
||||
.route("/config/auth", get(handlers::config::get_auth_config))
|
||||
.route("/config/auth", patch(handlers::config::update_auth_config))
|
||||
|
||||
Reference in New Issue
Block a user