From dff4d455e07d639b82a0bed814f41d0656e9b6d0 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 21 Sep 2024 14:03:45 +0300 Subject: cleanup --- internal/client/tui/submit.go | 51 ------------------------------------------- 1 file changed, 51 deletions(-) delete mode 100644 internal/client/tui/submit.go (limited to 'internal/client/tui/submit.go') diff --git a/internal/client/tui/submit.go b/internal/client/tui/submit.go deleted file mode 100644 index cc1ff0d..0000000 --- a/internal/client/tui/submit.go +++ /dev/null @@ -1,51 +0,0 @@ -package tui - -import ( - "context" - "errors" - "fmt" - "log" - "os" - "time" - - "codeberg.org/snonux/gos/internal/config/client" - config "codeberg.org/snonux/gos/internal/config/client" - "codeberg.org/snonux/gos/internal/easyhttp" - "codeberg.org/snonux/gos/internal/types" - tea "github.com/charmbracelet/bubbletea" -) - -func submitActionCmd(ctx context.Context, conf config.ClientConfig) tea.Cmd { - composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile) - log.Println("Submitting", composeFile) - - return submitEntryCmd(ctx, conf, composeFile, func() error { - // This is the cb to call when the entry was submitted succesfully - return nil - }) -} - -func submitEntryCmd(ctx context.Context, conf client.ClientConfig, composeFile string, cb func() error) tea.Cmd { - return finishedCmd(cb, submitEntry(ctx, conf, composeFile)) -} - -func submitEntry(ctx context.Context, conf client.ClientConfig, composeFile string) error { - if len(conf.Servers) == 0 { - return errors.New("no server configured") - } - - entry, err := types.NewEntryFromTextFile(composeFile) - if err != nil { - return err - } - - if err := easyhttp.PostData(ctx, "submit", conf.APIKey, &entry, conf.Servers...); err != nil { - return err - } - - timestamp := time.Now().Format("20060102-150405") - submittedFile := fmt.Sprintf("%s/submitted-%s.txt", conf.DataDir, timestamp) - - log.Println("Renaming", composeFile, "to", submittedFile) - return os.Rename(composeFile, submittedFile) -} -- cgit v1.2.3