chore: 提交所有工作进度 — SaaS 后端增强、Admin UI、桌面端集成
包含大量 SaaS 平台改进、Admin 管理后台更新、桌面端集成完善、 文档同步、测试文件重构等内容。为 QA 测试准备干净工作树。
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
//! 应用状态
|
||||
|
||||
use sqlx::SqlitePool;
|
||||
use sqlx::PgPool;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use tokio::sync::RwLock;
|
||||
@@ -10,7 +10,7 @@ use crate::config::SaaSConfig;
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
/// 数据库连接池
|
||||
pub db: SqlitePool,
|
||||
pub db: PgPool,
|
||||
/// 服务器配置 (可热更新)
|
||||
pub config: Arc<RwLock<SaaSConfig>>,
|
||||
/// JWT 密钥
|
||||
@@ -20,7 +20,7 @@ pub struct AppState {
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
pub fn new(db: SqlitePool, config: SaaSConfig) -> anyhow::Result<Self> {
|
||||
pub fn new(db: PgPool, config: SaaSConfig) -> anyhow::Result<Self> {
|
||||
let jwt_secret = config.jwt_secret()?;
|
||||
Ok(Self {
|
||||
db,
|
||||
@@ -29,4 +29,13 @@ impl AppState {
|
||||
rate_limit_entries: Arc::new(dashmap::DashMap::new()),
|
||||
})
|
||||
}
|
||||
|
||||
/// 清理过期的限流条目 (60 秒窗口外的记录)
|
||||
pub fn cleanup_rate_limit_entries(&self) {
|
||||
let window_start = Instant::now() - std::time::Duration::from_secs(60);
|
||||
self.rate_limit_entries.retain(|_, entries| {
|
||||
entries.retain(|&ts| ts > window_start);
|
||||
!entries.is_empty()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user