Skip to content

Commit

Permalink
Merge pull request #53 from picosh/post-filesize
Browse files Browse the repository at this point in the history
post filesize script
  • Loading branch information
antoniomika authored Nov 12, 2023
2 parents 01ffc21 + bd7f5fe commit f8e4071
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions cmd/scripts/file-size-sync/sync.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"encoding/binary"
"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")
picoDb := postgres.NewDB(picoCfg.DbURL, picoCfg.Logger)

posts, err := picoDb.FindPosts()
bail(err)
for _, post := range posts {
if post.Space == "imgs" {
continue
}
post.FileSize = binary.Size([]byte(post.Text))
_, err := picoDb.UpdatePost(post)
bail(err)
}
}

0 comments on commit f8e4071

Please sign in to comment.