fix: resolve conditional compilation and dead code warnings

This commit is contained in:
xfy 2026-06-08 16:11:24 +08:00
parent 012704d0a5
commit 717266db1e
8 changed files with 15 additions and 12 deletions

View File

@ -2,13 +2,12 @@
use dioxus::prelude::*;
#[cfg(feature = "server")]
use crate::api::utils::{db_conn_error, query_error};
#[cfg(feature = "server")]
use crate::auth::session::get_session_from_ctx;
use crate::db::pool::get_conn;
use crate::models::post::{Post, PostStats, PostStatus, Tag};
use crate::models::user::{User, UserRole};
#[cfg(feature = "server")]
use crate::utils::text::{auto_summary, count_words};
// ============================================================================

View File

@ -177,5 +177,4 @@ pub async fn upload_image(
})))
}
#[cfg(not(feature = "server"))]
pub async fn upload_image() {}

View File

@ -1,15 +1,15 @@
#![allow(clippy::unused_unit)]
use dioxus::prelude::*;
#[cfg(feature = "server")]
pub fn db_conn_error(e: impl std::fmt::Display) -> ServerFnError {
#[allow(dead_code)]
pub fn db_conn_error(e: impl std::fmt::Display) -> dioxus::prelude::ServerFnError {
tracing::error!("DB connection failed: {}", e);
ServerFnError::new(format!("数据库连接失败: {}", e))
dioxus::prelude::ServerFnError::new(format!("数据库连接失败: {}", e))
}
#[cfg(feature = "server")]
pub fn query_error(e: impl std::fmt::Display) -> ServerFnError {
#[allow(dead_code)]
pub fn query_error(e: impl std::fmt::Display) -> dioxus::prelude::ServerFnError {
tracing::error!("Query failed: {}", e);
ServerFnError::new(format!("查询失败: {}", e))
dioxus::prelude::ServerFnError::new(format!("查询失败: {}", e))
}

View File

@ -11,6 +11,7 @@ pub fn default_expiry() -> DateTime<Utc> {
Utc::now() + Duration::days(30)
}
#[cfg(feature = "server")]
pub fn parse_session_token(cookie_header: &str) -> Option<&str> {
cookie_header.split(';').map(|s| s.trim()).find_map(|pair| {
let mut parts = pair.splitn(2, '=');

View File

@ -4,6 +4,7 @@ pub const INPUT_CLASS: &str = "w-full px-4 py-2 border border-gray-200 dark:bord
pub const BUTTON_PRIMARY_CLASS: &str = "w-full py-2 px-4 bg-gray-900 dark:bg-[#dadadb] text-white dark:text-gray-900 font-medium rounded-full hover:opacity-80 transition-opacity cursor-pointer";
#[allow(dead_code)]
pub const BUTTON_SECONDARY_CLASS: &str = "px-6 py-2 bg-gray-200 dark:bg-[#333] text-gray-700 dark:text-[#dadadb] rounded-full font-medium hover:opacity-80 transition-opacity cursor-pointer";
#[component]

View File

@ -7,6 +7,7 @@ use crate::models::post::Post;
use crate::router::Route;
#[component]
#[allow(unused_variables)]
pub fn Posts() -> Element {
let mut posts_res = use_resource(list_posts);
let mut deleting = use_signal(|| None::<i32>);

View File

@ -3,9 +3,10 @@ use dioxus::prelude::*;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::JsCast;
use crate::api::posts::{create_post, get_post_by_id, update_post, CreatePostResponse, SinglePostResponse};
use crate::api::posts::{get_post_by_id, SinglePostResponse};
#[cfg(target_arch = "wasm32")]
use crate::api::posts::{create_post, update_post, CreatePostResponse};
use crate::components::write_skeleton::WriteSkeleton;
use crate::models::post::PostStatus;
use crate::router::Route;
#[component]

View File

@ -1,2 +1,3 @@
pub mod time;
#[cfg(feature = "server")]
pub mod text;