diff options
| author | Paul Buetow <paul@buetow.org> | 2024-09-21 14:03:45 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-09-21 14:03:45 +0300 |
| commit | dff4d455e07d639b82a0bed814f41d0656e9b6d0 (patch) | |
| tree | 56289a6fd80a00a9724992ab9cb8b3d7215ebedf /internal/client/tui/submit.go | |
| parent | 780ade3dc066afb8a43be824373414f3d316ebd6 (diff) | |
cleanup
Diffstat (limited to 'internal/client/tui/submit.go')
| -rw-r--r-- | internal/client/tui/submit.go | 51 |
1 files changed, 0 insertions, 51 deletions
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) -} |
