summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2024-07-28 18:46:41 +0300
committerPaul Buetow <paul@buetow.org>2024-07-28 18:46:41 +0300
commit7fc95c18f169f0bfe0a5bc8a239ec5853619ec59 (patch)
tree930f45563c8254205e2cac60b2eff234649362ed
parent8572fca487d124518e46f4fad1919cf98c5ae56a (diff)
initial posting real data over
-rw-r--r--internal/client/tui/submit.go9
-rw-r--r--internal/types/entry.go16
2 files changed, 22 insertions, 3 deletions
diff --git a/internal/client/tui/submit.go b/internal/client/tui/submit.go
index 90143d6..7e1f15c 100644
--- a/internal/client/tui/submit.go
+++ b/internal/client/tui/submit.go
@@ -14,17 +14,20 @@ import (
func submitAction(ctx context.Context, conf config.ClientConfig) tea.Cmd {
composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile)
- return submitMessage(ctx, conf, composeFile, func() error {
+ return submitEntry(ctx, conf, composeFile, func() error {
// This is the callback to call
return nil
})
}
-func submitMessage(ctx context.Context, conf client.ClientConfig, filePath string, callback func() error) tea.Cmd {
+func submitEntry(ctx context.Context, conf client.ClientConfig, filePath string, callback func() error) tea.Cmd {
servers, err := conf.Servers()
if err == nil {
var entry types.Entry
- err = easyhttp.PostData(ctx, "submit", conf.APIKey, &entry, servers...)
+ entry, err = types.NewEntryFromFile(filePath)
+ if err == nil {
+ err = easyhttp.PostData(ctx, "submit", conf.APIKey, &entry, servers...)
+ }
}
return func() tea.Msg {
diff --git a/internal/types/entry.go b/internal/types/entry.go
index ca2a742..695c786 100644
--- a/internal/types/entry.go
+++ b/internal/types/entry.go
@@ -4,6 +4,7 @@ import (
"crypto/sha256"
"encoding/json"
"fmt"
+ "os"
"strings"
"sync"
)
@@ -63,6 +64,21 @@ func NewEntryFromCopy(other Entry) (Entry, error) {
return e.Update(other)
}
+func NewEntryFromFile(filePath string) (Entry, error) {
+ var e Entry
+ data, err := os.ReadFile(filePath)
+ if err != nil {
+ return e, err
+ }
+ e.Body = string(data)
+ if e.ID == "" {
+ e.ID = fmt.Sprintf("%x", sha256.Sum256([]byte(e.Body)))
+ }
+ e.initialize()
+ e.Checksum()
+ return e, nil
+}
+
func (e *Entry) initialize() {
e.mu = &sync.Mutex{}
e.checksumDirty = true