| 115 | } |
| 116 | |
| 117 | function setAutoUpdate(uid, isEnabled) { |
| 118 | const db = sqliteClient.getDb(); |
| 119 | const targetUid = uid || sqliteClient.defaultUserId; |
| 120 | |
| 121 | try { |
| 122 | const result = db.prepare('UPDATE users SET auto_update_enabled = ? WHERE uid = ?').run(isEnabled ? 1 : 0, targetUid); |
| 123 | |
| 124 | // If no rows were updated, the user might not exist, so create them |
| 125 | if (result.changes === 0) { |
| 126 | const now = Math.floor(Date.now() / 1000); |
| 127 | const stmt = db.prepare('INSERT OR REPLACE INTO users (uid, display_name, email, created_at, auto_update_enabled) VALUES (?, ?, ?, ?, ?)'); |
| 128 | stmt.run(targetUid, 'User', 'user@example.com', now, isEnabled ? 1 : 0); |
| 129 | } |
| 130 | |
| 131 | return { success: true }; |
| 132 | } catch (error) { |
| 133 | console.error('SQLite: Error setting auto-update:', error); |
| 134 | throw error; |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | module.exports = { |
| 139 | getPresets, |