This repository has been archived on 2026-05-05. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
el-ide/vessels/el-ide-server/src/api/plugins.rs
T
Will Anderson b2c22e6616 rename crates/ → vessels/ — El's word for buildable units
Per the consolidation onto El: 'crates' is the Rust word, 'vessel' is
El's (per spec/language.md §15). The directory rename is the structural
marker that this slot holds an El buildable unit, even if its current
contents are still Rust pending port.

Mechanical: git mv crates vessels, sed workspace members and any path
dependencies, update CI workflow paths, update README references.
Cross-repo path dependencies (`../foo/crates/bar`) updated workspace-
wide so cargo metadata still resolves where the Rust still builds.
2026-04-30 15:34:20 -05:00

78 lines
2.3 KiB
Rust

//! Plugins API — list, install, remove, enable, disable.
//!
//! All mutation operations use POST with a JSON body containing `name`
//! to avoid path-parameter routing conflicts with Axum 0.7/matchit 0.7.
use axum::{extract::State, http::StatusCode, Json};
use serde::{Deserialize, Serialize};
use el_plugin_host::Plugin;
use crate::AppState;
type ApiResult<T> = Result<Json<T>, (StatusCode, Json<serde_json::Value>)>;
fn api_err(code: StatusCode, msg: impl Into<String>) -> (StatusCode, Json<serde_json::Value>) {
(code, Json(serde_json::json!({ "error": msg.into() })))
}
#[derive(Debug, Deserialize)]
pub struct NameRequest {
pub name: String,
}
#[derive(Debug, Serialize)]
pub struct OkResponse {
pub ok: bool,
}
/// GET /api/plugins
pub async fn list_plugins(State(state): State<AppState>) -> ApiResult<Vec<Plugin>> {
let host = state.plugins.lock().await;
Ok(Json(host.list()))
}
/// POST /api/plugins/install — body: { name }
pub async fn install_plugin(
State(state): State<AppState>,
Json(req): Json<NameRequest>,
) -> ApiResult<Plugin> {
let mut host = state.plugins.lock().await;
host.install(&req.name)
.map(Json)
.map_err(|e| api_err(StatusCode::BAD_REQUEST, e.to_string()))
}
/// POST /api/plugins/remove — body: { name }
pub async fn remove_plugin(
State(state): State<AppState>,
Json(req): Json<NameRequest>,
) -> ApiResult<OkResponse> {
let mut host = state.plugins.lock().await;
host.remove(&req.name)
.map(|_| Json(OkResponse { ok: true }))
.map_err(|e| api_err(StatusCode::BAD_REQUEST, e.to_string()))
}
/// POST /api/plugins/enable — body: { name }
pub async fn enable_plugin(
State(state): State<AppState>,
Json(req): Json<NameRequest>,
) -> ApiResult<OkResponse> {
let mut host = state.plugins.lock().await;
host.enable(&req.name)
.map(|_| Json(OkResponse { ok: true }))
.map_err(|e| api_err(StatusCode::BAD_REQUEST, e.to_string()))
}
/// POST /api/plugins/disable — body: { name }
pub async fn disable_plugin(
State(state): State<AppState>,
Json(req): Json<NameRequest>,
) -> ApiResult<OkResponse> {
let mut host = state.plugins.lock().await;
host.disable(&req.name)
.map(|_| Json(OkResponse { ok: true }))
.map_err(|e| api_err(StatusCode::BAD_REQUEST, e.to_string()))
}