refactor(core): move doc handler to core and split API.md per app
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
4761e88c81
commit
b651b6af66
|
|
@ -1,40 +1,10 @@
|
||||||
use axum::{
|
use axum::response::IntoResponse;
|
||||||
http::{header, HeaderMap, HeaderValue, StatusCode},
|
|
||||||
response::IntoResponse,
|
|
||||||
};
|
|
||||||
|
|
||||||
use plc_platform_core::util::response::ApiErr;
|
use plc_platform_core::util::response::ApiErr;
|
||||||
|
|
||||||
pub async fn get_api_md() -> Result<impl IntoResponse, ApiErr> {
|
pub async fn get_api_md() -> Result<impl IntoResponse, ApiErr> {
|
||||||
let content = tokio::fs::read_to_string("API.md")
|
plc_platform_core::handler::doc::serve_markdown("docs/api-feeder.md").await
|
||||||
.await
|
|
||||||
.map_err(|err| {
|
|
||||||
tracing::error!("Failed to read API.md: {}", err);
|
|
||||||
ApiErr::NotFound("API.md not found".to_string(), None)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
|
||||||
headers.insert(
|
|
||||||
header::CONTENT_TYPE,
|
|
||||||
HeaderValue::from_static("text/markdown; charset=utf-8"),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok((StatusCode::OK, headers, content))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn get_readme_md() -> Result<impl IntoResponse, ApiErr> {
|
pub async fn get_readme_md() -> Result<impl IntoResponse, ApiErr> {
|
||||||
let content = tokio::fs::read_to_string("README.md")
|
plc_platform_core::handler::doc::serve_markdown("README.md").await
|
||||||
.await
|
|
||||||
.map_err(|err| {
|
|
||||||
tracing::error!("Failed to read README.md: {}", err);
|
|
||||||
ApiErr::NotFound("README.md not found".to_string(), None)
|
|
||||||
})?;
|
|
||||||
|
|
||||||
let mut headers = HeaderMap::new();
|
|
||||||
headers.insert(
|
|
||||||
header::CONTENT_TYPE,
|
|
||||||
HeaderValue::from_static("text/markdown; charset=utf-8"),
|
|
||||||
);
|
|
||||||
|
|
||||||
Ok((StatusCode::OK, headers, content))
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
pub mod doc;
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
use axum::response::IntoResponse;
|
||||||
|
use plc_platform_core::util::response::ApiErr;
|
||||||
|
|
||||||
|
pub async fn get_api_md() -> Result<impl IntoResponse, ApiErr> {
|
||||||
|
plc_platform_core::handler::doc::serve_markdown("docs/api-ops.md").await
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn get_readme_md() -> Result<impl IntoResponse, ApiErr> {
|
||||||
|
plc_platform_core::handler::doc::serve_markdown("README.md").await
|
||||||
|
}
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
pub mod app;
|
pub mod app;
|
||||||
|
pub mod handler;
|
||||||
pub mod router;
|
pub mod router;
|
||||||
|
|
||||||
pub use app::{run, test_state, AppState};
|
pub use app::{run, test_state, AppState};
|
||||||
|
|
|
||||||
|
|
@ -1 +1,2 @@
|
||||||
|
pub mod doc;
|
||||||
pub mod log;
|
pub mod log;
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,23 @@
|
||||||
|
use axum::{
|
||||||
|
http::{header, HeaderMap, HeaderValue, StatusCode},
|
||||||
|
response::IntoResponse,
|
||||||
|
};
|
||||||
|
|
||||||
|
use crate::util::response::ApiErr;
|
||||||
|
|
||||||
|
pub async fn serve_markdown(path: &str) -> Result<impl IntoResponse, ApiErr> {
|
||||||
|
let content = tokio::fs::read_to_string(path)
|
||||||
|
.await
|
||||||
|
.map_err(|err| {
|
||||||
|
tracing::error!("Failed to read {}: {}", path, err);
|
||||||
|
ApiErr::NotFound(format!("{} not found", path), None)
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let mut headers = HeaderMap::new();
|
||||||
|
headers.insert(
|
||||||
|
header::CONTENT_TYPE,
|
||||||
|
HeaderValue::from_static("text/markdown; charset=utf-8"),
|
||||||
|
);
|
||||||
|
|
||||||
|
Ok((StatusCode::OK, headers, content))
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
# 运转系统 API
|
||||||
|
|
||||||
|
## 健康检查
|
||||||
|
|
||||||
|
- `GET /api/health` — 返回应用名称和状态
|
||||||
|
|
||||||
|
## 日志
|
||||||
|
|
||||||
|
- `GET /api/logs` — 拉取日志内容
|
||||||
|
- `GET /api/logs/stream` — SSE 增量推送
|
||||||
|
|
||||||
|
## 文档
|
||||||
|
|
||||||
|
- `GET /api/docs/api-md` — 获取 API 文档
|
||||||
|
- `GET /api/docs/readme-md` — 获取 README
|
||||||
Loading…
Reference in New Issue