feat(webui): add renaming a state path
All checks were successful
main / main (push) Successful in 1m39s
main / deploy (push) Has been skipped
main / publish (push) Has been skipped

Closes #9
This commit is contained in:
Julien Dessaux 2025-04-22 00:02:00 +02:00
parent d084a07bb5
commit 3192078b05
Signed by: adyxax
GPG key ID: F92E51B86E07177E
3 changed files with 101 additions and 0 deletions

View file

@ -166,6 +166,28 @@ func (db *DB) LoadStates() ([]model.State, error) {
return states, nil
}
// Returns (true, nil) on successful save
func (db *DB) SaveState(state *model.State) (bool, error) {
_, err := db.Exec(
`UPDATE states
SET lock = ?,
path = ?
WHERE id = ?`,
state.Lock,
state.Path,
state.Id)
if err != nil {
var sqliteErr sqlite3.Error
if errors.As(err, &sqliteErr) {
if sqliteErr.Code == sqlite3.ErrNo(sqlite3.ErrConstraint) {
return false, nil
}
}
return false, fmt.Errorf("failed to update state id %s: %w", state.Id, err)
}
return true, nil
}
// returns true in case of lock mismatch
func (db *DB) SetState(path string, accountId uuid.UUID, data []byte, lock string) (bool, error) {
encryptedData, err := db.dataEncryptionKey.EncryptAES256(data)