diff --git a/src/api/posts.rs b/src/api/posts.rs index 9ddc3da..77b0778 100644 --- a/src/api/posts.rs +++ b/src/api/posts.rs @@ -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}; // ============================================================================ diff --git a/src/api/upload.rs b/src/api/upload.rs index b2f9f33..ed52b88 100644 --- a/src/api/upload.rs +++ b/src/api/upload.rs @@ -177,5 +177,4 @@ pub async fn upload_image( }))) } -#[cfg(not(feature = "server"))] -pub async fn upload_image() {} + diff --git a/src/api/utils.rs b/src/api/utils.rs index 370b8a0..106e3eb 100644 --- a/src/api/utils.rs +++ b/src/api/utils.rs @@ -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)) } diff --git a/src/auth/session.rs b/src/auth/session.rs index 78d9e1c..7f30c92 100644 --- a/src/auth/session.rs +++ b/src/auth/session.rs @@ -11,6 +11,7 @@ pub fn default_expiry() -> DateTime { 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, '='); diff --git a/src/components/forms.rs b/src/components/forms.rs index ec85a05..e36cec2 100644 --- a/src/components/forms.rs +++ b/src/components/forms.rs @@ -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] diff --git a/src/pages/admin/posts.rs b/src/pages/admin/posts.rs index 5a5ae43..389e12a 100644 --- a/src/pages/admin/posts.rs +++ b/src/pages/admin/posts.rs @@ -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::); diff --git a/src/pages/admin/write.rs b/src/pages/admin/write.rs index 8369edf..628023e 100644 --- a/src/pages/admin/write.rs +++ b/src/pages/admin/write.rs @@ -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] diff --git a/src/utils/mod.rs b/src/utils/mod.rs index c3578c1..e381a9e 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,2 +1,3 @@ pub mod time; +#[cfg(feature = "server")] pub mod text;