From 24d0d0f4981488353e08e46b75beaa1247259caf Mon Sep 17 00:00:00 2001 From: Umputun Date: Sun, 24 Dec 2017 13:29:16 -0600 Subject: [PATCH] allow passing timestamp to create, clear on rest level --- app/main.go | 8 +++++++- app/migrator/disqus.go | 5 ----- app/rest/server.go | 3 ++- app/store/bolt.go | 4 +++- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/app/main.go b/app/main.go index 28cc2410..b254cc66 100644 --- a/app/main.go +++ b/app/main.go @@ -101,7 +101,13 @@ func importComments(dataStore store.Interface) error { if err != nil { return errors.Wrapf(err, "can't open import file %s", opts.ImportCommand.InputFile) } - defer fh.Close() + + defer func() { + if err = fh.Close(); err != nil { + log.Printf("[WARN] can't close %s, %s", opts.ImportCommand.InputFile, err) + } + }() + return importer.Import(fh, opts.ImportCommand.SiteID) } diff --git a/app/migrator/disqus.go b/app/migrator/disqus.go index 7a288ca2..4225a639 100644 --- a/app/migrator/disqus.go +++ b/app/migrator/disqus.go @@ -17,11 +17,6 @@ type Disqus struct { DataStore store.Interface } -type disqusXML struct { - Threads []disqusThread `xml:"thread"` - Comments []disqusComment `xml:"post"` -} - type disqusThread struct { UID string `xml:"id,attr"` Forum string `xml:"forum"` diff --git a/app/rest/server.go b/app/rest/server.go index 79aafb43..892f4269 100644 --- a/app/rest/server.go +++ b/app/rest/server.go @@ -105,7 +105,8 @@ func (s *Server) createCommentCtrl(w http.ResponseWriter, r *http.Request) { return } - comment.ID = "" // don't allow user to define ID, force auto-gen + comment.ID = "" // don't allow user to define ID, force auto-gen + comment.Timestamp = time.Time{} // reset time, force auto-gen comment.Text = template.HTMLEscapeString(comment.Text) comment.User.IP = strings.Split(r.RemoteAddr, ":")[0] diff --git a/app/store/bolt.go b/app/store/bolt.go index 13f2cebe..0541ef69 100644 --- a/app/store/bolt.go +++ b/app/store/bolt.go @@ -44,8 +44,10 @@ func (b *BoltDB) Create(comment Comment) (string, error) { if comment.ID == "" { comment.ID = makeCommentID() } + if comment.Timestamp.IsZero() { + comment.Timestamp = time.Now() + } - comment.Timestamp = time.Now() comment.Votes = make(map[string]bool) err := b.Update(func(tx *bolt.Tx) error {