refactor(web,health): 消除硬编码路径 — 统一 resolveMediaUrl + 动态 base_url
1. 新增 resolveMediaUrl() 工具函数,统一处理 storage_path 前缀和 JWT token 2. MediaLibrary 和 MediaPicker 改用 resolveMediaUrl,消除重复逻辑 3. banner_handler 不再硬编码 localhost:3000,改为从 Host header 动态构建 base_url
This commit is contained in:
@@ -136,7 +136,17 @@ where
|
||||
.or(params.tenant_id)
|
||||
.ok_or_else(|| AppError::Validation("缺少 tenant_id".to_string()))?;
|
||||
|
||||
let base_url = "http://localhost:3000".to_string();
|
||||
let base_url = headers
|
||||
.get("host")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.map(|h| {
|
||||
if h.starts_with("localhost") || h.starts_with("127.0.0.1") {
|
||||
format!("http://{}", h)
|
||||
} else {
|
||||
format!("https://{}", h)
|
||||
}
|
||||
})
|
||||
.unwrap_or_else(|| "http://localhost:3000".to_string());
|
||||
let result = banner_service::list_public_banners(&state, tenant_id, &base_url).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user