diff --git a/cmd/backend/config.go b/cmd/backend/config.go index 787e9f5..42d53a6 100644 --- a/cmd/backend/config.go +++ b/cmd/backend/config.go @@ -20,10 +20,10 @@ type Config struct { Description string Domain string FirebaseKey string + ImgDir string Link string LogFile string PDFDir string - PicsDir string Port string Title string Version string @@ -44,13 +44,13 @@ func newConfig() *Config { CookieExpiryHours: 24 * 30, DBName: "cpolis", FirebaseKey: "/etc/cpolis/serviceAccountKey.json", + ImgDir: "/var/www/cpolis/images", LogFile: "/var/log/cpolis.log", MaxBannerHeight: 1080, MaxBannerWidth: 1920, MaxImgHeight: 1080, MaxImgWidth: 1920, PDFDir: "/var/www/cpolis/pdfs", - PicsDir: "/var/www/cpolis/pics", Port: ":1664", Version: "v0.16.0", WebDir: "/var/www/cpolis/web", @@ -113,10 +113,10 @@ func (c *Config) handleCliArgs() error { flag.StringVar(&c.Description, "desc", c.Description, "channel description") flag.StringVar(&c.Domain, "domain", c.Domain, "domain name") flag.StringVar(&c.FirebaseKey, "firebase", c.FirebaseKey, "Firebase service account key file") + flag.StringVar(&c.ImgDir, "pics", c.ImgDir, "pictures directory") flag.StringVar(&c.Link, "link", c.Link, "channel Link") flag.StringVar(&c.LogFile, "log", c.LogFile, "log file") flag.StringVar(&c.PDFDir, "pdfs", c.PDFDir, "pdf directory") - flag.StringVar(&c.PicsDir, "pics", c.PicsDir, "pictures directory") flag.StringVar(&c.Title, "title", c.Title, "channel title") flag.StringVar(&c.WebDir, "web", c.WebDir, "web directory") flag.IntVar(&c.CookieExpiryHours, "cookie-expiry-hours", c.CookieExpiryHours, "cookies expire after this amount of hours") @@ -220,6 +220,18 @@ func (c *Config) setupConfig(cliConfig *Config) error { return fmt.Errorf("error setting up file: %v", err) } + if cliConfig.ImgDir != defaultConfig.ImgDir { + c.ImgDir = cliConfig.ImgDir + } + c.ImgDir, err = filepath.Abs(c.ImgDir) + if err != nil { + return fmt.Errorf("error setting absolute filepath for PicsDir: %v", err) + } + c.ImgDir, err = mkDir(c.ImgDir, 0700) + if err != nil { + return fmt.Errorf("error setting up directory: %v", err) + } + if cliConfig.Link != defaultConfig.Link { c.Link = cliConfig.Link } @@ -264,18 +276,6 @@ func (c *Config) setupConfig(cliConfig *Config) error { return fmt.Errorf("error setting up directory: %v", err) } - if cliConfig.PicsDir != defaultConfig.PicsDir { - c.PicsDir = cliConfig.PicsDir - } - c.PicsDir, err = filepath.Abs(c.PicsDir) - if err != nil { - return fmt.Errorf("error setting absolute filepath for PicsDir: %v", err) - } - c.PicsDir, err = mkDir(c.PicsDir, 0700) - if err != nil { - return fmt.Errorf("error setting up directory: %v", err) - } - if cliConfig.Port != defaultConfig.Port { c.Port = cliConfig.Port } diff --git a/cmd/backend/docx.go b/cmd/backend/docx.go index 37f895c..8e34e07 100644 --- a/cmd/backend/docx.go +++ b/cmd/backend/docx.go @@ -45,7 +45,7 @@ func ConvertToMarkdown(c *Config, filename string) ([]byte, error) { } defer image.Close() - newImageName, err := SaveImage(image, c.MaxImgHeight, c.MaxImgWidth, c.PicsDir) + newImageName, err := SaveImage(image, c.MaxImgHeight, c.MaxImgWidth, c.ImgDir) if err != nil { return nil, fmt.Errorf("error saving image %v: %v", name, err) } diff --git a/cmd/backend/images.go b/cmd/backend/images.go index a8dce5f..861f5d4 100644 --- a/cmd/backend/images.go +++ b/cmd/backend/images.go @@ -48,7 +48,7 @@ func SaveImage(src io.Reader, maxHeight, maxWidth int, path string) (string, err } func CleanUpImages(c *Config, db *DB) error { - if err := filepath.Walk(c.PicsDir, func(path string, info fs.FileInfo, err error) error { + if err := filepath.Walk(c.ImgDir, func(path string, info fs.FileInfo, err error) error { if err != nil { return fmt.Errorf("error walking images filepath: %v", err) } diff --git a/cmd/calls/images.go b/cmd/calls/images.go index e8edab2..de316b0 100644 --- a/cmd/calls/images.go +++ b/cmd/calls/images.go @@ -16,6 +16,6 @@ func ServeImage(c *b.Config, s map[string]*f.Session) http.HandlerFunc { } } - http.ServeFile(w, r, filepath.Join(c.PicsDir, r.PathValue("pic"))) + http.ServeFile(w, r, filepath.Join(c.ImgDir, r.PathValue("pic"))) } }