From 4b574bd79a57d82e7d65bc92b3842ae1187cd362 Mon Sep 17 00:00:00 2001 From: lkhsss Date: Wed, 7 Jan 2026 11:26:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E5=9C=A8=E4=B8=8A=E4=BC=A0=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=BA=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 ++- data.sqlite | Bin 28672 -> 28672 bytes src/constant.rs | 7 ++++--- src/handlers.rs | 6 +++--- src/main.rs | 19 ++++++++++--------- 5 files changed, 19 insertions(+), 16 deletions(-) diff --git a/.gitignore b/.gitignore index a803f50..a3c8ba4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /target -/dist \ No newline at end of file +/dist +*.sqlite \ No newline at end of file diff --git a/data.sqlite b/data.sqlite index 8cd72866c0409c60154e3804d699a5ab087cb646..7e7df0a46f41f29ab394798b69350e5b9760a29e 100644 GIT binary patch delta 419 zcmZp8z}WDBae_3X;zSu|M#YT@^YsMnZ^7tYAT!oQb+e=q-8{^$I6fffQSKI_lU z3A0K7$TR0+b=3)~=p%XD=@;PA!VhOc9uQmi-kwi2&YGBUC_G7!84jJhN;{am~uh zE~#=(ws0yBt4z)|%{Mdj^-WKod_ match e { - sqlx::Error::Database(_) => Common::failure("该账号已注册".to_string()), + // sqlx::Error::Database(_) => Common::failure("该账号已注册".to_string()), _ => Common::failure(e.to_string()), }, } @@ -85,11 +85,11 @@ pub async fn login( pub async fn logout(mut auth_session: AuthSession, username: String) -> impl IntoResponse { match auth_session.logout().await { Ok(_) => { - info!("用户:[{}]退出登陆", username); + info!("用户:[{}]退出登陆", auth_session.user.unwrap().username); Common::success("退出登陆成功".to_string()) } Err(e) => { - error!("用户:[{}]退出登陆失败:{:?}", username, e); + error!("用户:[{}]退出登陆失败:{:?}", auth_session.user.unwrap().username, e); Common::success(format!("退出登陆失败:{:?}", e)) } } diff --git a/src/main.rs b/src/main.rs index 1e82c35..c8392d3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,8 +26,8 @@ use constant::DIST_DIR; use constant::PORT; use database::Database; -use crate::constant::DATABASE; use crate::constant::PROJECT_DIR; +use crate::constant::{BROWER_OPEN, DATABASE}; use crate::routers::api_routes_init; #[tokio::main] @@ -87,20 +87,21 @@ async fn main() { .with_state(db) .layer(auth_layer) .layer(TraceLayer::new_for_http()); - // .route("/test", get())// 测试接口 //.layer(middleware::from_fn(logging_middleware)); let listener = tokio::net::TcpListener::bind(format!("0.0.0.0:{PORT}")) .await .unwrap(); info!("成功启用服务:http://0.0.0.0:{PORT}"); - match webbrowser::open(&format!("http://127.0.0.1:{PORT}")) { - Ok(_) => info!( - "成功打开浏览器并访问: {}", - &format!("http://127.0.0.1:{PORT}") - ), - Err(e) => error!("无法打开浏览器: {}", e), - }; + if BROWER_OPEN { + match webbrowser::open(&format!("http://127.0.0.1:{PORT}")) { + Ok(_) => info!( + "成功打开浏览器并访问: {}", + &format!("http://127.0.0.1:{PORT}") + ), + Err(e) => error!("无法打开浏览器: {}", e), + }; + } axum::serve(listener, app) .with_graceful_shutdown(shutdown_signal(deletion_task.abort_handle())) .await