| 3217 | } |
| 3218 | |
| 3219 | async fn reply_permission( |
| 3220 | State(state): State<Arc<ServerState>>, |
| 3221 | Path(id): Path<String>, |
| 3222 | Json(req): Json<ReplyPermissionRequest>, |
| 3223 | ) -> Result<Json<bool>> { |
| 3224 | match req.reply.as_str() { |
| 3225 | "once" | "always" | "reject" => {} |
| 3226 | _ => { |
| 3227 | return Err(ApiError::BadRequest( |
| 3228 | "Invalid reply; expected `once`, `always`, or `reject`".to_string(), |
| 3229 | )); |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | let mut pending = PERMISSION_REQUESTS.write().await; |
| 3234 | let permission = pending |
| 3235 | .remove(&id) |
| 3236 | .ok_or_else(|| ApiError::NotFound(format!("Permission request not found: {}", id)))?; |
| 3237 | |
| 3238 | if req.reply == "reject" { |
| 3239 | pending.retain(|_, item| item.session_id != permission.session_id); |
| 3240 | } |
| 3241 | |
| 3242 | state.broadcast( |
| 3243 | &serde_json::json!({ |
| 3244 | "type": "permission.replied", |
| 3245 | "requestID": id, |
| 3246 | "sessionID": permission.session_id, |
| 3247 | "reply": req.reply, |
| 3248 | "message": req.message, |
| 3249 | }) |
| 3250 | .to_string(), |
| 3251 | ); |
| 3252 | Ok(Json(true)) |
| 3253 | } |
| 3254 | |
| 3255 | fn project_routes() -> Router<Arc<ServerState>> { |
| 3256 | Router::new() |