- commit
- 3c844e7
- parent
- ccf8adf
- author
- Antonio Mika
- date
- 2022-08-26 17:16:07 +0000 UTC
Move configuration options and add the ability to delete image files from CMS
5 files changed,
+29,
-12
+4,
-4
1@@ -47,16 +47,16 @@ func NewConfigSite() *shared.ConfigSite {
2 cfg := shared.ConfigSite{
3 SubdomainsEnabled: subdomainsEnabled,
4 CustomdomainsEnabled: customdomainsEnabled,
5- StorageDir: storageDir,
6- MinioURL: minioURL,
7- MinioUser: minioUser,
8- MinioPass: minioPass,
9 ConfigCms: config.ConfigCms{
10 Domain: domain,
11 Email: email,
12 Port: port,
13 Protocol: protocol,
14 DbURL: dbURL,
15+ StorageDir: storageDir,
16+ MinioURL: minioURL,
17+ MinioUser: minioUser,
18+ MinioPass: minioPass,
19 Description: "a premium image hosting service for hackers.",
20 IntroText: intro,
21 Space: "imgs",
1@@ -27,10 +27,6 @@ type ConfigSite struct {
2 config.ConfigURL
3 SubdomainsEnabled bool
4 CustomdomainsEnabled bool
5- StorageDir string
6- MinioURL string
7- MinioUser string
8- MinioPass string
9 }
10
11 func (c *ConfigSite) GetSiteData() *SitePageData {
+17,
-3
1@@ -6,6 +6,7 @@ import (
2
3 "git.sr.ht/~erock/pico/db"
4 "git.sr.ht/~erock/pico/db/postgres"
5+ "git.sr.ht/~erock/pico/imgs/storage"
6 "git.sr.ht/~erock/pico/wish/cms/config"
7 "git.sr.ht/~erock/pico/wish/cms/ui/account"
8 "git.sr.ht/~erock/pico/wish/cms/ui/common"
9@@ -100,11 +101,23 @@ func Middleware(cfg *config.ConfigCms, urls config.ConfigURL) bm.Handler {
10
11 dbpool := postgres.NewDB(cfg)
12
13+ var st storage.ObjectStorage
14+ if cfg.MinioURL == "" {
15+ st, err = storage.NewStorageFS(cfg.StorageDir)
16+ } else {
17+ st, err = storage.NewStorageMinio(cfg.MinioURL, cfg.MinioUser, cfg.MinioPass)
18+ }
19+
20+ if err != nil {
21+ logger.Fatal(err)
22+ }
23+
24 m := model{
25 cfg: cfg,
26 urls: urls,
27 publicKey: key,
28 dbpool: dbpool,
29+ st: st,
30 sshUser: sshUser,
31 status: statusInit,
32 menuChoice: unsetChoice,
33@@ -129,6 +142,7 @@ type model struct {
34 urls config.ConfigURL
35 publicKey string
36 dbpool db.DB
37+ st storage.ObjectStorage
38 user *db.User
39 err error
40 sshUser string
41@@ -226,7 +240,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
42 m.user = msg
43 m.username = username.NewModel(m.dbpool, m.user, m.sshUser)
44 m.info = info.NewModel(m.cfg, m.urls, m.user)
45- m.posts = posts.NewModel(m.cfg, m.urls, m.dbpool, m.user)
46+ m.posts = posts.NewModel(m.cfg, m.urls, m.dbpool, m.user, m.st)
47 m.keys = keys.NewModel(m.cfg, m.dbpool, m.user)
48 m.createAccount = account.NewCreateModel(m.cfg, m.dbpool, m.publicKey)
49 }
50@@ -235,7 +249,7 @@ func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
51 case statusInit:
52 m.username = username.NewModel(m.dbpool, m.user, m.sshUser)
53 m.info = info.NewModel(m.cfg, m.urls, m.user)
54- m.posts = posts.NewModel(m.cfg, m.urls, m.dbpool, m.user)
55+ m.posts = posts.NewModel(m.cfg, m.urls, m.dbpool, m.user, m.st)
56 m.keys = keys.NewModel(m.cfg, m.dbpool, m.user)
57 m.createAccount = account.NewCreateModel(m.cfg, m.dbpool, m.publicKey)
58 if m.user == nil {
59@@ -267,7 +281,7 @@ func updateChildren(msg tea.Msg, m model) (model, tea.Cmd) {
60 cmd = newCmd
61
62 if m.posts.Exit {
63- m.posts = posts.NewModel(m.cfg, m.urls, m.dbpool, m.user)
64+ m.posts = posts.NewModel(m.cfg, m.urls, m.dbpool, m.user, m.st)
65 m.status = statusReady
66 } else if m.posts.Quit {
67 m.status = statusQuitting
+4,
-0
1@@ -15,6 +15,10 @@ type ConfigCms struct {
2 Email string
3 Protocol string
4 DbURL string
5+ StorageDir string
6+ MinioURL string
7+ MinioUser string
8+ MinioPass string
9 Description string
10 IntroText string
11 Space string
+4,
-1
1@@ -8,6 +8,7 @@ import (
2 tea "github.com/charmbracelet/bubbletea"
3
4 "git.sr.ht/~erock/pico/db"
5+ "git.sr.ht/~erock/pico/imgs/storage"
6 "git.sr.ht/~erock/pico/wish/cms/config"
7 "git.sr.ht/~erock/pico/wish/cms/ui/common"
8
9@@ -50,6 +51,7 @@ type Model struct {
10 cfg *config.ConfigCms
11 urls config.ConfigURL
12 dbpool db.DB
13+ st storage.ObjectStorage
14 user *db.User
15 posts []*db.Post
16 styles common.Styles
17@@ -82,7 +84,7 @@ func (m *Model) UpdatePaging(msg tea.Msg) {
18 }
19
20 // NewModel creates a new model with defaults.
21-func NewModel(cfg *config.ConfigCms, urls config.ConfigURL, dbpool db.DB, user *db.User) Model {
22+func NewModel(cfg *config.ConfigCms, urls config.ConfigURL, dbpool db.DB, user *db.User, stor storage.ObjectStorage) Model {
23 logger := cfg.Logger
24 st := common.DefaultStyles()
25
26@@ -94,6 +96,7 @@ func NewModel(cfg *config.ConfigCms, urls config.ConfigURL, dbpool db.DB, user *
27 return Model{
28 cfg: cfg,
29 dbpool: dbpool,
30+ st: stor,
31 user: user,
32 styles: st,
33 pager: p,