Total refactoring performed

This commit is contained in:
AG
2025-12-20 18:53:49 +02:00
parent e41bb6b588
commit 5877ca3544
29 changed files with 3888 additions and 344 deletions

24
server/db.ts Normal file
View File

@@ -0,0 +1,24 @@
import Database from 'better-sqlite3';
const db = new Database('session_state.db');
// Initialize tables
db.exec(`
CREATE TABLE IF NOT EXISTS sessions (
id TEXT PRIMARY KEY,
state TEXT NOT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
)
`);
const getSessionStmt = db.prepare('SELECT state FROM sessions WHERE id = ?');
const upsertSessionStmt = db.prepare('INSERT INTO sessions (id, state) VALUES (?, ?) ON CONFLICT(id) DO UPDATE SET state = excluded.state, updated_at = CURRENT_TIMESTAMP');
export function getPersistedSession(id: string) {
const row = getSessionStmt.get(id) as { state: string } | undefined;
return row ? JSON.parse(row.state) : null;
}
export function persistSession(id: string, state: any) {
upsertSessionStmt.run(id, JSON.stringify(state));
}