repos / pico

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

commit
9be8122
parent
a8f4b4e
author
Eric Bower
date
2023-11-12 04:40:12 +0000 UTC
post filesize
1 files changed,  +45, -0
A cmd/scripts/file-size-sync/sync.go
+45, -0
 1@@ -0,0 +1,45 @@
 2+package main
 3+
 4+import (
 5+	"log"
 6+	"os"
 7+
 8+	"github.com/picosh/pico/db/postgres"
 9+	"github.com/picosh/pico/wish/cms/config"
10+	"go.uber.org/zap"
11+)
12+
13+func createLogger() *zap.SugaredLogger {
14+	logger, err := zap.NewProduction()
15+	if err != nil {
16+		log.Fatal(err)
17+	}
18+
19+	return logger.Sugar()
20+}
21+
22+func bail(err error) {
23+	if err != nil {
24+		panic(err)
25+	}
26+}
27+
28+func main() {
29+	logger := createLogger()
30+
31+	picoCfg := config.NewConfigCms()
32+	picoCfg.Logger = logger
33+	picoCfg.DbURL = os.Getenv("DATABASE_URL")
34+	picoCfg.MinioURL = os.Getenv("MINIO_URL")
35+	picoCfg.MinioUser = os.Getenv("MINIO_ROOT_USER")
36+	picoCfg.MinioPass = os.Getenv("MINIO_ROOT_PASSWORD")
37+	picoDb := postgres.NewDB(picoCfg.DbURL, picoCfg.Logger)
38+
39+	posts, err := picoDb.FindPosts()
40+	bail(err)
41+	for _, post := range posts {
42+		post.FileSize = len(post.Text)
43+		_, err := picoDb.UpdatePost(post)
44+		bail(err)
45+	}
46+}