2020-01-02 00:03:07 +01:00
|
|
|
package config
|
|
|
|
|
2020-05-05 18:26:44 +02:00
|
|
|
import (
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
|
|
|
)
|
2020-01-31 15:29:06 +01:00
|
|
|
|
2020-01-02 00:03:07 +01:00
|
|
|
// DetachServer returns true if server should detach from console (daemon mode).
|
|
|
|
func (c *Config) DetachServer() bool {
|
2020-04-13 18:08:21 +02:00
|
|
|
return c.params.DetachServer
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// HttpServerHost returns the built-in HTTP server host name or IP address (empty for all interfaces).
|
|
|
|
func (c *Config) HttpServerHost() string {
|
2020-04-13 18:08:21 +02:00
|
|
|
if c.params.HttpServerHost == "" {
|
2020-01-02 00:03:07 +01:00
|
|
|
return "0.0.0.0"
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:08:21 +02:00
|
|
|
return c.params.HttpServerHost
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// HttpServerPort returns the built-in HTTP server port.
|
|
|
|
func (c *Config) HttpServerPort() int {
|
2020-04-13 18:08:21 +02:00
|
|
|
if c.params.HttpServerPort == 0 {
|
2020-01-02 00:03:07 +01:00
|
|
|
return 2342
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:08:21 +02:00
|
|
|
return c.params.HttpServerPort
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// HttpServerMode returns the server mode.
|
|
|
|
func (c *Config) HttpServerMode() string {
|
2020-04-13 18:08:21 +02:00
|
|
|
if c.params.HttpServerMode == "" {
|
2020-01-02 00:03:07 +01:00
|
|
|
if c.Debug() {
|
|
|
|
return "debug"
|
|
|
|
}
|
|
|
|
|
|
|
|
return "release"
|
|
|
|
}
|
|
|
|
|
2020-04-13 18:08:21 +02:00
|
|
|
return c.params.HttpServerMode
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// HttpServerPassword returns the password for the user interface (optional).
|
|
|
|
func (c *Config) HttpServerPassword() string {
|
2020-04-13 18:08:21 +02:00
|
|
|
return c.params.HttpServerPassword
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
// TemplateExists returns true if a template with the given name exists (e.g. index.tmpl).
|
|
|
|
func (c *Config) TemplateExists(name string) bool {
|
|
|
|
return fs.FileExists(filepath.Join(c.TemplatesPath(), name))
|
2020-05-05 18:26:44 +02:00
|
|
|
}
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
// DefaultTemplate returns the name of the default template (e.g. index.tmpl).
|
|
|
|
func (c *Config) DefaultTemplate() string {
|
|
|
|
if c.TemplateExists(c.Settings().Templates.Default) {
|
2020-05-05 18:26:44 +02:00
|
|
|
return c.Settings().Templates.Default
|
|
|
|
}
|
|
|
|
|
|
|
|
return "index.tmpl"
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
// FaviconsPath returns the favicons path.
|
|
|
|
func (c *Config) FaviconsPath() string {
|
|
|
|
return filepath.Join(c.StaticPath(), "favicons")
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
// StaticPath returns the static server assets path (//server/static/*).
|
|
|
|
func (c *Config) StaticPath() string {
|
|
|
|
return filepath.Join(c.AssetsPath(), "static")
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
2020-05-31 02:09:52 +02:00
|
|
|
// StaticBuildPath returns the static build path (//server/static/build/*).
|
|
|
|
func (c *Config) StaticBuildPath() string {
|
|
|
|
return filepath.Join(c.StaticPath(), "build")
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|