diff options
| author | Paul Buetow <paul@buetow.org> | 2024-07-28 22:03:37 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2024-07-28 22:03:37 +0300 |
| commit | f36f21e1f1610b76caecbfab844f0462a9ba040c (patch) | |
| tree | 2c43b85f22bdf8b064d31c6bc51a70ded3e44d03 | |
| parent | 9535dc386f568132f986b672528189faec8842bf (diff) | |
submitted posts get archived
| -rw-r--r-- | internal/client/tui/submit.go | 8 | ||||
| -rw-r--r-- | internal/server/repository/repository.go | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/internal/client/tui/submit.go b/internal/client/tui/submit.go index 34f668d..49e1007 100644 --- a/internal/client/tui/submit.go +++ b/internal/client/tui/submit.go @@ -3,6 +3,8 @@ package tui import ( "context" "fmt" + "os" + "time" "codeberg.org/snonux/gos/internal/config/client" config "codeberg.org/snonux/gos/internal/config/client" @@ -15,8 +17,10 @@ func submitAction(ctx context.Context, conf config.ClientConfig) tea.Cmd { composeFile := fmt.Sprintf("%s/%s", conf.DataDir, conf.ComposeFile) return submitEntry(ctx, conf, composeFile, func() error { - // This is the callback to call - return nil + // This is the callback to call when the entry was submitted succesfully + timestamp := time.Now().Format("20060102-150405") + submittedFile := fmt.Sprintf("%s/submitted-%s.txt", conf.DataDir, timestamp) + return os.Rename(composeFile, submittedFile) }) } diff --git a/internal/server/repository/repository.go b/internal/server/repository/repository.go index 381560c..0b7d162 100644 --- a/internal/server/repository/repository.go +++ b/internal/server/repository/repository.go @@ -80,14 +80,18 @@ func (r Repository) load() error { var errs []error for _, filePath := range filePaths { + log.Println("loading entry", filePath) + bytes, err := r.fs.ReadFile(filePath) if err != nil { continue } + entry, err := types.NewEntry(bytes) if err != err { continue } + if err := r.put(entry); err != nil { errs = append(errs, err) } |
