summaryrefslogtreecommitdiff
path: root/internal/storer
diff options
context:
space:
mode:
Diffstat (limited to 'internal/storer')
-rw-r--r--internal/storer/storer.go24
1 files changed, 10 insertions, 14 deletions
diff --git a/internal/storer/storer.go b/internal/storer/storer.go
index 99da8b8..96ca9be 100644
--- a/internal/storer/storer.go
+++ b/internal/storer/storer.go
@@ -6,8 +6,8 @@ import (
"time"
"github.com/dgraph-io/badger"
+ "github.com/google/uuid"
"github.com/neonxp/sendsafe/internal/encryption"
- "github.com/rs/xid"
)
type Store struct {
@@ -49,10 +49,10 @@ func (s *Store) Save(text string, pin string, ttl int) (string, error) {
return "", err
}
- id := xid.New()
+ id := uuid.New()
err = s.db.Update(func(txn *badger.Txn) error {
return txn.SetEntry(&badger.Entry{
- Key: id.Bytes(),
+ Key: []byte(id.String()),
Value: buf.Bytes(),
ExpiresAt: uint64(time.Now().Add(time.Duration(ttl) * time.Minute).Unix()),
})
@@ -65,11 +65,7 @@ func (s *Store) IsEncrypted(id string) (bool, error) {
var encrypted bool
return encrypted, s.db.View(func(txn *badger.Txn) error {
- uid, err := xid.FromString(id)
- if err != nil {
- return err
- }
- value, err := txn.Get(uid.Bytes())
+ value, err := txn.Get([]byte(id))
if err != nil {
return err
}
@@ -88,11 +84,7 @@ func (s *Store) Get(id string, pin string) (string, error) {
var text string
return text, s.db.Update(func(txn *badger.Txn) error {
- uid, err := xid.FromString(id)
- if err != nil {
- return err
- }
- value, err := txn.Get(uid.Bytes())
+ value, err := txn.Get([]byte(id))
if err != nil {
return err
}
@@ -114,7 +106,7 @@ func (s *Store) Get(id string, pin string) (string, error) {
return err
}
}
- return txn.Delete(uid.Bytes())
+ return txn.Delete([]byte(id))
})
}
@@ -126,3 +118,7 @@ type memo struct {
Text string
Encrypted bool
}
+
+func (m *memo) Read(p []byte) (n int, err error) {
+ panic("not implemented") // TODO: Implement
+}