- commit
- 550b987
- parent
- dcf93cb
- author
- Antonio Mika
- date
- 2023-11-10 19:51:22 +0000 UTC
Set correct updated at when creating a post
3 files changed,
+9,
-6
+3,
-2
1@@ -231,8 +231,8 @@ const (
2 sqlInsertPost = `
3 INSERT INTO posts
4 (user_id, filename, slug, title, text, description, publish_at, hidden, cur_space,
5- file_size, mime_type, shasum, data, expires_at)
6- VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14)
7+ file_size, mime_type, shasum, data, expires_at, updated_at)
8+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
9 RETURNING id`
10 sqlInsertUser = `INSERT INTO app_users DEFAULT VALUES returning id`
11 sqlInsertTag = `INSERT INTO post_tags (post_id, name) VALUES($1, $2) RETURNING id;`
12@@ -730,6 +730,7 @@ func (me *PsqlDB) InsertPost(post *db.Post) (*db.Post, error) {
13 post.Shasum,
14 post.Data,
15 post.ExpiresAt,
16+ post.UpdatedAt,
17 ).Scan(&id)
18 if err != nil {
19 return nil, err
+3,
-2
1@@ -139,6 +139,8 @@ func (h *UploadImgHandler) writeImg(s ssh.Session, data *PostMetaData) error {
2 return err
3 }
4
5+ modTime := time.Unix(data.Mtime, 0)
6+
7 if len(data.OrigText) == 0 {
8 err = h.removePost(data)
9 if err != nil {
10@@ -175,6 +177,7 @@ func (h *UploadImgHandler) writeImg(s ssh.Session, data *PostMetaData) error {
11 Slug: data.Slug,
12 Text: data.Text,
13 Title: data.Title,
14+ UpdatedAt: &modTime,
15 }
16 _, err := h.DBPool.InsertPost(&insertPost)
17 if err != nil {
18@@ -194,8 +197,6 @@ func (h *UploadImgHandler) writeImg(s ssh.Session, data *PostMetaData) error {
19 }
20 }
21 } else {
22- modTime := time.Unix(data.Mtime, 0)
23-
24 if data.Shasum == data.Cur.Shasum && modTime.Equal(*data.Cur.UpdatedAt) {
25 h.Cfg.Logger.Infof("(%s) found, but image is identical, skipping", data.Filename)
26 return nil
+3,
-2
1@@ -232,6 +232,8 @@ func (h *ScpUploadHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
2 return "", err
3 }
4
5+ modTime := time.Unix(entry.Mtime, 0)
6+
7 // if the file is empty we remove it from our database
8 if len(origText) == 0 {
9 // skip empty files from being added to db
10@@ -264,6 +266,7 @@ func (h *ScpUploadHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
11 Text: metadata.Text,
12 Title: metadata.Title,
13 ExpiresAt: metadata.ExpiresAt,
14+ UpdatedAt: &modTime,
15 }
16 post, err = h.DBPool.InsertPost(&insertPost)
17 if err != nil {
18@@ -295,8 +298,6 @@ func (h *ScpUploadHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
19 }
20 }
21 } else {
22- modTime := time.Unix(entry.Mtime, 0)
23-
24 if metadata.Text == post.Text && modTime.Equal(*post.UpdatedAt) {
25 logger.Infof("(%s) found, but text is identical, skipping", filename)
26 curl := shared.NewCreateURL(h.Cfg)