Files
Genarrative/server-rs/crates/api-server/src/frontend_runtime_config.rs
T
kdletters 623e007fae
Project CI / AI game creator shell Rust shard 2/4 (push) Successful in 7m36s
Project CI / AI game creator shell Rust shard 3/4 (push) Successful in 7m37s
Project CI / AI game creator shell Rust shard 4/4 (push) Successful in 7m42s
Project CI / AI game creator shell Rust shard 1/4 (push) Successful in 7m51s
Project CI / AI game creator shell Rust smoke (push) Successful in 1m55s
Project CI / AI game creator shell Rust crates (push) Successful in 4m15s
Project CI / Repository checks (push) Successful in 4m45s
Project CI / Frontend tests (push) Successful in 7m47s
Project CI / Native shell tests (push) Successful in 9m33s
Project CI / Backend tests (push) Successful in 10m9s
Project CI / AI game creator shell web tests (push) Successful in 4m38s
完善客户端发布渠道并接入模板库灰度
区分发布渠道与系统,支持 dev、release 和自定义渠道
允许网站通过服务端配置选择客户端下载检测渠道
接入模板库灰度权限并阻断退出和切号后的异步操作
补齐发布、下载、灰度与会话竞态测试及当前规范
2026-09-20 12:12:49 +08:00

75 lines
2.3 KiB
Rust

use axum::{
extract::{Extension, State},
http::{HeaderMap, StatusCode, header},
response::{IntoResponse, Response},
};
use serde::Serialize;
use serde_json::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 agc_template_library_enabled: bool,
}
pub async fn get_frontend_runtime_config(
State(state): State<AppState>,
Extension(request_context): Extension<RequestContext>,
headers: HeaderMap,
) -> Result<Response, 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(),
}))
})?;
let agc_template_library_enabled = state
.is_agc_template_library_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((
[
(header::CACHE_CONTROL, "no-store"),
(header::VARY, "Authorization"),
],
json_success_body(
Some(&request_context),
FrontendRuntimeConfigResponse {
image_editor_agent_sidebar_enabled,
agc_template_library_enabled,
},
),
)
.into_response())
}