repos / pico

pico services - prose.sh, pastes.sh, imgs.sh, feeds.sh, pgs.sh
git clone https://github.com/picosh/pico.git

commit
3583e4a
parent
17c7257
author
Antonio Mika
date
2022-08-08 19:36:07 +0000 UTC
Fixed slug being filename when file contents are the same and allow cms post management for future posts
5 files changed,  +47, -5
M .env.example
+3, -3
 1@@ -14,7 +14,7 @@ LISTS_HOST=
 2 LISTS_SSH_PORT=2222
 3 LISTS_WEB_PORT=3000
 4 LISTS_PROM_PORT=9222
 5-LISTS_DOMAIN=lists.pico.sh:3000
 6+LISTS_DOMAIN=lists.dev.pico.sh:3000
 7 LISTS_EMAIL=hello@pico.sh
 8 LISTS_SUBDOMAINS=1
 9 LISTS_CUSTOMDOMAINS=1
10@@ -32,7 +32,7 @@ PASTES_HOST=
11 PASTES_SSH_PORT=2222
12 PASTES_WEB_PORT=3000
13 PASTES_PROM_PORT=9222
14-PASTES_DOMAIN=pastes.pico.sh:3001
15+PASTES_DOMAIN=pastes.dev.pico.sh:3001
16 PASTES_EMAIL=hello@pico.sh
17 PASTES_SUBDOMAINS=1
18 PASTES_CUSTOMDOMAINS=1
19@@ -50,7 +50,7 @@ PROSE_HOST=
20 PROSE_SSH_PORT=2222
21 PROSE_WEB_PORT=3000
22 PROSE_PROM_PORT=9222
23-PROSE_DOMAIN=prose.pico.sh:3002
24+PROSE_DOMAIN=prose.dev.pico.sh:3002
25 PROSE_EMAIL=hello@pico.sh
26 PROSE_SUBDOMAINS=1
27 PROSE_CUSTOMDOMAINS=1
M db/db.go
+1, -0
1@@ -108,6 +108,7 @@ type DB interface {
2 	FindPosts() ([]*Post, error)
3 	FindPost(postID string) (*Post, error)
4 	FindPostsForUser(userID string, space string) ([]*Post, error)
5+	FindAllPostsForUser(userID string, space string) ([]*Post, error)
6 	FindPostsBeforeDate(date *time.Time, space string) ([]*Post, error)
7 	FindUpdatedPostsForUser(userID string, space string) ([]*Post, error)
8 	FindPostWithFilename(filename string, userID string, space string) (*Post, error)
M db/postgres/storage.go
+41, -0
 1@@ -50,6 +50,15 @@ const (
 2 		publish_at::date <= CURRENT_DATE AND
 3 		cur_space = $2
 4 	ORDER BY publish_at DESC`
 5+	sqlSelectAllPostsForUser = `
 6+	SELECT posts.id, user_id, filename, slug, title, text, description, publish_at,
 7+		app_users.name as username, posts.updated_at
 8+	FROM posts
 9+	LEFT OUTER JOIN app_users ON app_users.id = posts.user_id
10+	WHERE
11+		user_id = $1 AND
12+		cur_space = $2
13+	ORDER BY publish_at DESC`
14 	sqlSelectPostsByTag = `
15 	SELECT posts.id, user_id, filename, slug, title, text, description, publish_at,
16 		app_users.name as username, posts.updated_at
17@@ -569,6 +578,38 @@ func (me *PsqlDB) FindPostsForUser(userID string, space string) ([]*db.Post, err
18 	return posts, nil
19 }
20 
21+func (me *PsqlDB) FindAllPostsForUser(userID string, space string) ([]*db.Post, error) {
22+	var posts []*db.Post
23+	rs, err := me.Db.Query(sqlSelectAllPostsForUser, userID, space)
24+	if err != nil {
25+		return posts, err
26+	}
27+	for rs.Next() {
28+		post := &db.Post{}
29+		err := rs.Scan(
30+			&post.ID,
31+			&post.UserID,
32+			&post.Filename,
33+			&post.Slug,
34+			&post.Title,
35+			&post.Text,
36+			&post.Description,
37+			&post.PublishAt,
38+			&post.Username,
39+			&post.UpdatedAt,
40+		)
41+		if err != nil {
42+			return posts, err
43+		}
44+
45+		posts = append(posts, post)
46+	}
47+	if rs.Err() != nil {
48+		return posts, rs.Err()
49+	}
50+	return posts, nil
51+}
52+
53 func (me *PsqlDB) FindPosts() ([]*db.Post, error) {
54 	var posts []*db.Post
55 	rs, err := me.Db.Query(sqlSelectPosts)
M filehandlers/post_handler.go
+1, -1
1@@ -154,7 +154,7 @@ func (h *ScpUploadHandler) Write(s ssh.Session, entry *utils.FileEntry) (string,
2 	} else {
3 		if text == post.Text {
4 			logger.Infof("(%s) found, but text is identical, skipping", filename)
5-			return h.Cfg.FullPostURL(user.Name, filename, h.Cfg.IsSubdomains(), true), nil
6+			return h.Cfg.FullPostURL(user.Name, metadata.Slug, h.Cfg.IsSubdomains(), true), nil
7 		}
8 
9 		logger.Infof("(%s) found, updating record", filename)
M wish/cms/ui/posts/posts.go
+1, -1
1@@ -318,7 +318,7 @@ func LoadPosts(m Model) tea.Cmd {
2 
3 func (m Model) fetchPosts(userID string) tea.Cmd {
4 	return func() tea.Msg {
5-		posts, _ := m.dbpool.FindPostsForUser(userID, m.cfg.Space)
6+		posts, _ := m.dbpool.FindAllPostsForUser(userID, m.cfg.Space)
7 		loader := PostLoader{
8 			Posts: posts,
9 		}