feat: file logging on client, logs command to fetch last N lines
This commit is contained in:
parent
23bbb5b603
commit
db3fa9f416
6 changed files with 130 additions and 9 deletions
|
|
@ -135,6 +135,29 @@ pub async fn window_screenshot(
|
|||
}
|
||||
}
|
||||
|
||||
/// GET /sessions/:id/logs?lines=100
|
||||
pub async fn logs(
|
||||
Path(session_id): Path<String>,
|
||||
Query(params): Query<std::collections::HashMap<String, String>>,
|
||||
State(state): State<AppState>,
|
||||
) -> impl IntoResponse {
|
||||
let lines: u32 = params.get("lines").and_then(|v| v.parse().ok()).unwrap_or(100);
|
||||
match dispatch(&state, &session_id, "logs", |rid| {
|
||||
ServerMessage::LogsRequest { request_id: rid, lines }
|
||||
}).await {
|
||||
Ok(ClientMessage::LogsResponse { content, log_path, .. }) => (
|
||||
StatusCode::OK,
|
||||
Json(serde_json::json!({ "content": content, "log_path": log_path, "lines": lines })),
|
||||
).into_response(),
|
||||
Ok(ClientMessage::Error { message, .. }) => (
|
||||
StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Json(serde_json::json!({ "error": message })),
|
||||
).into_response(),
|
||||
Ok(_) => (StatusCode::BAD_GATEWAY, Json(serde_json::json!({ "error": "Unexpected response" }))).into_response(),
|
||||
Err(e) => e.into_response(),
|
||||
}
|
||||
}
|
||||
|
||||
/// POST /sessions/:id/screenshot
|
||||
pub async fn request_screenshot(
|
||||
Path(session_id): Path<String>,
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ async fn main() -> anyhow::Result<()> {
|
|||
.route("/sessions/:id/prompt", post(api::prompt_user))
|
||||
.route("/sessions/:id/windows", get(api::list_windows))
|
||||
.route("/sessions/:id/windows/minimize-all", post(api::minimize_all))
|
||||
.route("/sessions/:id/logs", get(api::logs))
|
||||
.route("/sessions/:id/windows/:window_id/screenshot", post(api::window_screenshot))
|
||||
.route("/sessions/:id/windows/:window_id/focus", post(api::focus_window))
|
||||
.route("/sessions/:id/windows/:window_id/maximize", post(api::maximize_and_focus))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue