| 51 | } |
| 52 | |
| 53 | function updatePreset(id, { title, prompt }, uid) { |
| 54 | const db = sqliteClient.getDb(); |
| 55 | const now = Math.floor(Date.now() / 1000); |
| 56 | const query = ` |
| 57 | UPDATE prompt_presets |
| 58 | SET title = ?, prompt = ?, sync_state = 'dirty', updated_at = ? |
| 59 | WHERE id = ? AND uid = ? AND is_default = 0 |
| 60 | `; |
| 61 | |
| 62 | try { |
| 63 | const result = db.prepare(query).run(title, prompt, now, id, uid); |
| 64 | if (result.changes === 0) { |
| 65 | throw new Error('Preset not found, is default, or permission denied'); |
| 66 | } |
| 67 | return { changes: result.changes }; |
| 68 | } catch (err) { |
| 69 | console.error('SQLite: Failed to update preset:', err); |
| 70 | throw err; |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | function deletePreset(id, uid) { |
| 75 | const db = sqliteClient.getDb(); |