25cac367c6
新增 SpacetimeDB 灰度配置表与后端判定链路 新增后台灰度发布页面和两段式 Gate Key 选择器 将画布 Agent 入口接入灰度配置与运行时能力下发 修复灰度配置刷新读取空本地缓存的问题 补充灰度规则和后台下拉维护约定文档
54 lines
1.6 KiB
Rust
54 lines
1.6 KiB
Rust
use axum::{
|
|
Json,
|
|
extract::{Extension, State},
|
|
http::{HeaderMap, StatusCode},
|
|
};
|
|
use serde::Serialize;
|
|
use serde_json::{Value, json};
|
|
|
|
use crate::{
|
|
api_response::json_success_body, auth::optional_access_token_from_headers,
|
|
http_error::AppError, request_context::RequestContext, state::AppState,
|
|
};
|
|
|
|
#[derive(Debug, Serialize)]
|
|
#[serde(rename_all = "camelCase")]
|
|
pub struct FrontendRuntimeConfigResponse {
|
|
pub image_editor_agent_sidebar_enabled: bool,
|
|
}
|
|
|
|
pub async fn get_frontend_runtime_config(
|
|
State(state): State<AppState>,
|
|
Extension(request_context): Extension<RequestContext>,
|
|
headers: HeaderMap,
|
|
) -> Result<Json<Value>, AppError> {
|
|
let authenticated = optional_access_token_from_headers(
|
|
&state,
|
|
"/api/runtime/frontend-config".to_string(),
|
|
headers,
|
|
request_context.request_id().to_string(),
|
|
)
|
|
.await?;
|
|
let user_id = authenticated
|
|
.as_ref()
|
|
.map(|authenticated| authenticated.claims().user_id());
|
|
let image_editor_agent_sidebar_enabled = state
|
|
.is_image_editor_agent_sidebar_enabled_for_user(user_id)
|
|
.await
|
|
.map_err(|error| {
|
|
AppError::from_status(StatusCode::BAD_GATEWAY)
|
|
.with_message("读取前端运行时配置失败")
|
|
.with_details(json!({
|
|
"provider": "spacetimedb",
|
|
"message": error.to_string(),
|
|
}))
|
|
})?;
|
|
|
|
Ok(json_success_body(
|
|
Some(&request_context),
|
|
FrontendRuntimeConfigResponse {
|
|
image_editor_agent_sidebar_enabled,
|
|
},
|
|
))
|
|
}
|