fix(health,miniprogram): 轮播图图片改用相对路径 + wx.downloadFile 解决 HTTP 限制
问题:微信小程序 <image> 不支持 HTTP URL,签名 URL 与 upload 中间件不兼容。 修复: 1. 公开轮播图 API 返回相对路径(/uploads/...)而非签名 URL 2. 小程序用 wx.downloadFile 下载图片后使用本地临时路径 3. 移除 banner_handler 中不再需要的 base_url/Host header 逻辑
This commit is contained in:
@@ -122,31 +122,14 @@ where
|
||||
pub async fn list_public_banners<S>(
|
||||
State(state): State<HealthState>,
|
||||
Query(params): Query<PublicBannerQuery>,
|
||||
headers: axum::http::HeaderMap,
|
||||
) -> Result<Json<ApiResponse<Vec<PublicBannerResp>>>, AppError>
|
||||
where
|
||||
HealthState: FromRef<S>,
|
||||
S: Clone + Send + Sync + 'static,
|
||||
{
|
||||
// 从 X-Tenant-Id 请求头或查询参数中解析租户 ID
|
||||
let tenant_id = headers
|
||||
.get("X-Tenant-Id")
|
||||
.and_then(|v| v.to_str().ok())
|
||||
.and_then(|v| v.parse::<uuid::Uuid>().ok())
|
||||
.or(params.tenant_id)
|
||||
let tenant_id = params
|
||||
.tenant_id
|
||||
.ok_or_else(|| AppError::Validation("缺少 tenant_id".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?;
|
||||
let result = banner_service::list_public_banners(&state, tenant_id).await?;
|
||||
Ok(Json(ApiResponse::ok(result)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user