allow passing timestamp to create, clear on rest level

This commit is contained in:
Umputun
2017-12-24 13:29:16 -06:00
parent d274593c79
commit 24d0d0f498
4 changed files with 12 additions and 8 deletions
+7 -1
View File
@@ -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)
}
-5
View File
@@ -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"`
+2 -1
View File
@@ -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]
+3 -1
View File
@@ -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 {