feat: add experience improvement module and system config storage (#1248)

- Add experience module for product telemetry
- Add system_config table for persistent settings
- Update privacy policy documentation
This commit is contained in:
tinkle-community
2025-12-19 13:57:08 +08:00
committed by GitHub
parent c81e6b0094
commit 97f58b49f4
12 changed files with 409 additions and 4 deletions

View File

@@ -115,6 +115,16 @@ func (s *Store) SetCryptoFuncs(encrypt, decrypt func(string) string) {
// initTables initializes all database tables
func (s *Store) initTables() error {
// Initialize system config table first
if _, err := s.db.Exec(`
CREATE TABLE IF NOT EXISTS system_config (
key TEXT PRIMARY KEY,
value TEXT NOT NULL
)
`); err != nil {
return fmt.Errorf("failed to create system_config table: %w", err)
}
// Initialize in dependency order
if err := s.User().initTables(); err != nil {
return fmt.Errorf("failed to initialize user tables: %w", err)
@@ -278,6 +288,25 @@ func (s *Store) DB() *sql.DB {
return s.db
}
// GetSystemConfig gets a system configuration value by key
func (s *Store) GetSystemConfig(key string) (string, error) {
var value string
err := s.db.QueryRow(`SELECT value FROM system_config WHERE key = ?`, key).Scan(&value)
if err == sql.ErrNoRows {
return "", nil
}
return value, err
}
// SetSystemConfig sets a system configuration value
func (s *Store) SetSystemConfig(key, value string) error {
_, err := s.db.Exec(`
INSERT INTO system_config (key, value) VALUES (?, ?)
ON CONFLICT(key) DO UPDATE SET value = excluded.value
`, key, value)
return err
}
// Transaction executes transaction
func (s *Store) Transaction(fn func(tx *sql.Tx) error) error {
tx, err := s.db.Begin()