refactor(database): unify database connections and add retry logic
Refactor LocalDataSource to reuse the shared database connection from database.ts, avoiding OPFS file handle conflicts. Add retry logic with exponential backoff for database open operations, particularly important for Web/OPFS environments. Also add dynamic theme support to chat input and message bubble styles, using theme colors instead of hardcoded values for better light/dark mode support. BREAKING CHANGE: Database initialization now requires userId to be passed explicitly for user-specific databases
This commit is contained in:
@@ -258,11 +258,11 @@ export const useAuthStore = create<AuthState>((set) => ({
|
||||
const savedUserId = await loadUserId();
|
||||
|
||||
if (savedUserId) {
|
||||
// 2. 用已知的 userId 提前初始化 DB
|
||||
// 2. 用已知的 userId 提前初始化 DB(数据库模块内部已处理重试)
|
||||
try {
|
||||
await initDatabase(savedUserId);
|
||||
} catch (dbErr) {
|
||||
console.warn('[AuthStore] DB 预初始化失败:', dbErr);
|
||||
console.warn('[AuthStore] DB 预初始化失败,将尝试在 API 成功后重新初始化:', dbErr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user