mirror of
https://codeberg.org/scip/anydb.git
synced 2025-12-17 04:20:59 +01:00
restructured data storage, values now have their own sub bucket
This commit is contained in:
43
app/attr.go
43
app/attr.go
@@ -20,17 +20,19 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strings"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
type DbAttr struct {
|
||||
Key string
|
||||
Val string
|
||||
Bin []byte
|
||||
Preview string
|
||||
Val []byte
|
||||
Args []string
|
||||
Tags []string
|
||||
File string
|
||||
Encrypted bool
|
||||
Binary bool
|
||||
}
|
||||
|
||||
func (attr *DbAttr) ParseKV() error {
|
||||
@@ -43,7 +45,7 @@ func (attr *DbAttr) ParseKV() error {
|
||||
}
|
||||
case 2:
|
||||
attr.Key = attr.Args[0]
|
||||
attr.Val = attr.Args[1]
|
||||
attr.Val = []byte(attr.Args[1])
|
||||
|
||||
if attr.Args[1] == "-" {
|
||||
attr.File = "-"
|
||||
@@ -51,7 +53,29 @@ func (attr *DbAttr) ParseKV() error {
|
||||
}
|
||||
|
||||
if attr.File != "" {
|
||||
return attr.GetFileValue()
|
||||
if err := attr.GetFileValue(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if attr.Binary {
|
||||
attr.Preview = "<encrypted-content>"
|
||||
} else {
|
||||
if len(attr.Val) > MaxValueWidth {
|
||||
attr.Preview = string(attr.Val)[0:MaxValueWidth] + "..."
|
||||
|
||||
if strings.Contains(attr.Preview, "\n") {
|
||||
parts := strings.Split(attr.Preview, "\n")
|
||||
if len(parts) > 0 {
|
||||
attr.Preview = parts[0]
|
||||
}
|
||||
}
|
||||
} else {
|
||||
attr.Preview = string(attr.Val)
|
||||
}
|
||||
}
|
||||
if attr.Encrypted {
|
||||
attr.Preview = "<encrypted-content>"
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -82,11 +106,12 @@ func (attr *DbAttr) GetFileValue() error {
|
||||
}
|
||||
|
||||
// poor man's text file test
|
||||
sdata := string(data)
|
||||
if utf8.ValidString(sdata) {
|
||||
attr.Val = sdata
|
||||
attr.Val = data
|
||||
|
||||
if utf8.ValidString(string(data)) {
|
||||
attr.Binary = false
|
||||
} else {
|
||||
attr.Bin = data
|
||||
attr.Binary = true
|
||||
}
|
||||
} else {
|
||||
// read from console stdin
|
||||
@@ -101,7 +126,7 @@ func (attr *DbAttr) GetFileValue() error {
|
||||
data += input + "\n"
|
||||
}
|
||||
|
||||
attr.Val = data
|
||||
attr.Val = []byte(data)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user