2020-01-02 00:03:07 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2020-01-21 13:59:41 +01:00
|
|
|
"fmt"
|
2020-01-02 00:03:07 +01:00
|
|
|
"os"
|
|
|
|
"os/exec"
|
|
|
|
"path/filepath"
|
|
|
|
|
2020-01-12 14:00:56 +01:00
|
|
|
"github.com/photoprism/photoprism/pkg/fs"
|
2020-01-02 00:03:07 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func findExecutable(configBin, defaultBin string) (result string) {
|
|
|
|
if configBin == "" {
|
|
|
|
result = defaultBin
|
|
|
|
} else {
|
|
|
|
result = configBin
|
|
|
|
}
|
|
|
|
|
|
|
|
if path, err := exec.LookPath(result); err == nil {
|
|
|
|
result = path
|
|
|
|
}
|
|
|
|
|
2020-01-12 14:00:56 +01:00
|
|
|
if !fs.FileExists(result) {
|
2020-01-02 00:03:07 +01:00
|
|
|
result = ""
|
|
|
|
}
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-01-21 13:59:41 +01:00
|
|
|
// CreateDirectories creates directories for storing photos, metadata and cache files.
|
2020-01-02 00:03:07 +01:00
|
|
|
func (c *Config) CreateDirectories() error {
|
2020-01-21 13:59:41 +01:00
|
|
|
createError := func(path string, err error) (result error) {
|
|
|
|
if fs.FileExists(path) {
|
|
|
|
result = fmt.Errorf("\"%s\" is a file, not a directory: please check your configuration", path)
|
|
|
|
} else {
|
|
|
|
result = fmt.Errorf("can't create \"%s\": please check configuration and permissions", path)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Debug(err)
|
|
|
|
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
2020-01-02 00:03:07 +01:00
|
|
|
if err := os.MkdirAll(c.OriginalsPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.OriginalsPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.ImportPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.ImportPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.ExportPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.ExportPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.ThumbnailsPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.ThumbnailsPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.ResourcesPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.ResourcesPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.SqlServerPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.SqlServerPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.TensorFlowModelPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.TensorFlowModelPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(c.HttpStaticBuildPath(), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(c.HttpStaticBuildPath(), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(filepath.Dir(c.PIDFilename()), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(filepath.Dir(c.PIDFilename()), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if err := os.MkdirAll(filepath.Dir(c.LogFilename()), os.ModePerm); err != nil {
|
2020-01-21 13:59:41 +01:00
|
|
|
return createError(filepath.Dir(c.LogFilename()), err)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigFile returns the config file name.
|
|
|
|
func (c *Config) ConfigFile() string {
|
|
|
|
return c.config.ConfigFile
|
|
|
|
}
|
|
|
|
|
|
|
|
// SettingsFile returns the user settings file name.
|
|
|
|
func (c *Config) SettingsFile() string {
|
|
|
|
return c.ConfigPath() + "/settings.yml"
|
|
|
|
}
|
|
|
|
|
|
|
|
// ConfigPath returns the config path.
|
|
|
|
func (c *Config) ConfigPath() string {
|
|
|
|
if c.config.ConfigPath == "" {
|
|
|
|
return c.AssetsPath() + "/config"
|
|
|
|
}
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.ConfigPath)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// PIDFilename returns the filename for storing the server process id (pid).
|
|
|
|
func (c *Config) PIDFilename() string {
|
|
|
|
if c.config.PIDFilename == "" {
|
|
|
|
return c.AssetsPath() + "/photoprism.pid"
|
|
|
|
}
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.PIDFilename)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// LogFilename returns the filename for storing server logs.
|
|
|
|
func (c *Config) LogFilename() string {
|
|
|
|
if c.config.LogFilename == "" {
|
|
|
|
return c.AssetsPath() + "/photoprism.log"
|
|
|
|
}
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.LogFilename)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// OriginalsPath returns the originals.
|
|
|
|
func (c *Config) OriginalsPath() string {
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.OriginalsPath)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ImportPath returns the import directory.
|
|
|
|
func (c *Config) ImportPath() string {
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.ImportPath)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExportPath returns the export directory.
|
|
|
|
func (c *Config) ExportPath() string {
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.ExportPath)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// SipsBin returns the sips binary file name.
|
|
|
|
func (c *Config) SipsBin() string {
|
|
|
|
return findExecutable(c.config.SipsBin, "sips")
|
|
|
|
}
|
|
|
|
|
|
|
|
// DarktableBin returns the darktable-cli binary file name.
|
|
|
|
func (c *Config) DarktableBin() string {
|
|
|
|
return findExecutable(c.config.DarktableBin, "darktable-cli")
|
|
|
|
}
|
|
|
|
|
|
|
|
// HeifConvertBin returns the heif-convert binary file name.
|
|
|
|
func (c *Config) HeifConvertBin() string {
|
|
|
|
return findExecutable(c.config.HeifConvertBin, "heif-convert")
|
|
|
|
}
|
|
|
|
|
|
|
|
// ExifToolBin returns the exiftool binary file name.
|
|
|
|
func (c *Config) ExifToolBin() string {
|
|
|
|
return findExecutable(c.config.ExifToolBin, "exiftool")
|
|
|
|
}
|
|
|
|
|
|
|
|
// CachePath returns the path to the cache.
|
|
|
|
func (c *Config) CachePath() string {
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.CachePath)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ThumbnailsPath returns the path to the cached thumbnails.
|
|
|
|
func (c *Config) ThumbnailsPath() string {
|
|
|
|
return c.CachePath() + "/thumbnails"
|
|
|
|
}
|
|
|
|
|
|
|
|
// AssetsPath returns the path to the assets.
|
|
|
|
func (c *Config) AssetsPath() string {
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.AssetsPath)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ResourcesPath returns the path to the app resources like static files.
|
|
|
|
func (c *Config) ResourcesPath() string {
|
|
|
|
if c.config.ResourcesPath == "" {
|
|
|
|
return c.AssetsPath() + "/resources"
|
|
|
|
}
|
|
|
|
|
2020-01-31 15:29:06 +01:00
|
|
|
return fs.Abs(c.config.ResourcesPath)
|
2020-01-02 00:03:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// ExamplesPath returns the example files path.
|
|
|
|
func (c *Config) ExamplesPath() string {
|
|
|
|
return c.ResourcesPath() + "/examples"
|
|
|
|
}
|
|
|
|
|
|
|
|
// TensorFlowModelPath returns the tensorflow model path.
|
|
|
|
func (c *Config) TensorFlowModelPath() string {
|
|
|
|
return c.ResourcesPath() + "/nasnet"
|
|
|
|
}
|
|
|
|
|
|
|
|
// NSFWModelPath returns the NSFW tensorflow model path.
|
|
|
|
func (c *Config) NSFWModelPath() string {
|
|
|
|
return c.ResourcesPath() + "/nsfw"
|
|
|
|
}
|