Skip to content

Commit

Permalink
post filesize
Browse files Browse the repository at this point in the history
  • Loading branch information
neurosnap committed Nov 12, 2023
1 parent a8f4b4e commit 9be8122
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions cmd/scripts/file-size-sync/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package main

import (
"log"
"os"

"github.com/picosh/pico/db/postgres"
"github.com/picosh/pico/wish/cms/config"
"go.uber.org/zap"
)

func createLogger() *zap.SugaredLogger {
logger, err := zap.NewProduction()
if err != nil {
log.Fatal(err)
}

return logger.Sugar()
}

func bail(err error) {
if err != nil {
panic(err)
}
}

func main() {
logger := createLogger()

picoCfg := config.NewConfigCms()
picoCfg.Logger = logger
picoCfg.DbURL = os.Getenv("DATABASE_URL")
picoCfg.MinioURL = os.Getenv("MINIO_URL")
picoCfg.MinioUser = os.Getenv("MINIO_ROOT_USER")
picoCfg.MinioPass = os.Getenv("MINIO_ROOT_PASSWORD")
picoDb := postgres.NewDB(picoCfg.DbURL, picoCfg.Logger)

posts, err := picoDb.FindPosts()
bail(err)
for _, post := range posts {
post.FileSize = len(post.Text)
_, err := picoDb.UpdatePost(post)
bail(err)
}
}

0 comments on commit 9be8122

Please sign in to comment.