From 371ebcf8f9a39a730368f30aa24c8964966b50d7 Mon Sep 17 00:00:00 2001 From: xfy Date: Fri, 5 Jun 2026 15:08:19 +0800 Subject: [PATCH] fix(upload): gate axum imports behind #[cfg(feature = "server")] Wrap all axum imports and constants with #[cfg(feature = "server")] to prevent WASM compilation failures. Provide a no-op stub for non-server builds. Fixes: error[E0433]: cannot find module or crate in scope --- src/api/upload.rs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/api/upload.rs b/src/api/upload.rs index aaaa302..b2f9f33 100644 --- a/src/api/upload.rs +++ b/src/api/upload.rs @@ -1,16 +1,20 @@ #![allow(clippy::unused_unit)] +#[cfg(feature = "server")] use axum::{ extract::Multipart, http::{HeaderMap, StatusCode}, response::Json, }; +#[cfg(feature = "server")] use serde_json::{json, Value}; #[cfg(feature = "server")] use crate::auth::session::parse_session_token; +#[cfg(feature = "server")] const ALLOWED_MIME_TYPES: &[&str] = &["image/jpeg", "image/png", "image/gif", "image/webp"]; +#[cfg(feature = "server")] const MAX_FILE_SIZE: usize = 5 * 1024 * 1024; // 5MB #[cfg(feature = "server")] @@ -174,15 +178,4 @@ pub async fn upload_image( } #[cfg(not(feature = "server"))] -pub async fn upload_image( - _headers: HeaderMap, - _multipart: Multipart, -) -> Result, (StatusCode, Json)> { - Err(( - StatusCode::SERVICE_UNAVAILABLE, - Json(json!({ - "success": false, - "error": "服务器功能未启用" - })), - )) -} +pub async fn upload_image() {}