2020-01-02 00:03:07 +01:00
|
|
|
package config
|
|
|
|
|
2020-05-05 18:26:44 +02:00
|
|
|
import (
|
|
|
|
"path/filepath"
|
2021-01-10 15:28:42 +01:00
|
|
|
"strings"
|
2020-05-05 18:26:44 +02:00
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
|
|
|
)
|
2020-01-31 15:29:06 +01:00
|
|
|
|
2022-04-06 17:46:41 +02:00
|
|
|
// DetachServer checks if server should detach from console (daemon mode).
|
2020-01-02 00:03:07 +01:00
|
|
|
func (c *Config) DetachServer() bool {
|
2020-12-18 20:42:12 +01:00
|
|
|
return c.options.DetachServer
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
// HttpHost returns the built-in HTTP server host name or IP address (empty for all interfaces).
|
|
|
|
func (c *Config) HttpHost() string {
|
2020-12-18 20:42:12 +01:00
|
|
|
if c.options.HttpHost == "" {
|
2020-01-02 00:03:07 +01:00
|
|
|
return "0.0.0.0"
|
|
|
|
}
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
return c.options.HttpHost
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
// HttpPort returns the built-in HTTP server port.
|
|
|
|
func (c *Config) HttpPort() int {
|
2020-12-18 20:42:12 +01:00
|
|
|
if c.options.HttpPort == 0 {
|
2020-01-02 00:03:07 +01:00
|
|
|
return 2342
|
|
|
|
}
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
return c.options.HttpPort
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-12-18 09:11:42 +01:00
|
|
|
// HttpMode returns the server mode.
|
|
|
|
func (c *Config) HttpMode() string {
|
2020-12-18 20:42:12 +01:00
|
|
|
if c.options.HttpMode == "" {
|
2020-01-02 00:03:07 +01:00
|
|
|
if c.Debug() {
|
|
|
|
return "debug"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "release"
|
|
|
|
}
|
|
|
|
|
2020-12-18 20:42:12 +01:00
|
|
|
return c.options.HttpMode
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2021-01-10 15:28:42 +01:00
|
|
|
// HttpCompression returns the http compression method (none or gzip).
|
|
|
|
func (c *Config) HttpCompression() string {
|
|
|
|
return strings.ToLower(strings.TrimSpace(c.options.HttpCompression))
|
|
|
|
}
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
// TemplatesPath returns the server templates path.
|
|
|
|
func (c *Config) TemplatesPath() string {
|
|
|
|
return filepath.Join(c.AssetsPath(), "templates")
|
2020-05-05 18:26:44 +02:00
|
|
|
}
|
|
|
|
|
2022-04-06 17:46:41 +02:00
|
|
|
// TemplateExists checks if a template with the given name exists (e.g. index.tmpl).
|
2020-05-31 02:09:52 +02:00
|
|
|
func (c *Config) TemplateExists(name string) bool {
|
|
|
|
return fs.FileExists(filepath.Join(c.TemplatesPath(), name))
|
2020-05-05 18:26:44 +02:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
// TemplateName returns the name of the default template (e.g. index.tmpl).
|
|
|
|
func (c *Config) TemplateName() string {
|
2020-10-08 08:52:03 +02:00
|
|
|
if s := c.Settings(); s != nil {
|
|
|
|
if c.TemplateExists(s.Templates.Default) {
|
|
|
|
return s.Templates.Default
|
|
|
|
}
|
2020-05-05 18:26:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return "index.tmpl"
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
// StaticPath returns the static assets path.
|
2020-05-31 02:09:52 +02:00
|
|
|
func (c *Config) StaticPath() string {
|
|
|
|
return filepath.Join(c.AssetsPath(), "static")
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:11:56 +02:00
|
|
|
// BuildPath returns the static build path.
|
|
|
|
func (c *Config) BuildPath() string {
|
2020-05-31 02:09:52 +02:00
|
|
|
return filepath.Join(c.StaticPath(), "build")
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
2020-06-26 16:11:56 +02:00
|
|
|
|
2021-11-25 17:24:53 +01:00
|
|
|
// ImgPath returns the path to static image files.
|
2020-06-26 16:11:56 +02:00
|
|
|
func (c *Config) ImgPath() string {
|
|
|
|
return filepath.Join(c.StaticPath(), "img")
|
|
|
|
}
|