photoprism/internal/config/config_customize.go

65 lines
1.6 KiB
Go
Raw Normal View History

2021-11-22 11:26:10 +01:00
package config
import (
"path"
2021-11-22 11:26:10 +01:00
"path/filepath"
"strings"
2021-11-22 11:36:46 +01:00
"github.com/photoprism/photoprism/internal/i18n"
"github.com/photoprism/photoprism/pkg/clean"
2021-11-22 11:36:46 +01:00
"github.com/photoprism/photoprism/pkg/fs"
2021-11-22 11:26:10 +01:00
)
// DefaultTheme returns the default user interface theme name.
func (c *Config) DefaultTheme() string {
if c.options.DefaultTheme == "" || c.NoSponsor() {
return "default"
}
return c.options.DefaultTheme
}
// DefaultLocale returns the default user interface language locale name.
func (c *Config) DefaultLocale() string {
if c.options.DefaultLocale == "" {
return i18n.Default.Locale()
}
return c.options.DefaultLocale
}
// WallpaperUri returns the login screen background image `URI`.
func (c *Config) WallpaperUri() string {
if c.NoSponsor() {
return ""
} else if strings.Contains(c.options.WallpaperUri, "/") {
return c.options.WallpaperUri
}
assetPath := "img/wallpaper"
// Empty URI?
if c.options.WallpaperUri == "" {
if !fs.PathExists(filepath.Join(c.StaticPath(), assetPath)) {
return ""
}
c.options.WallpaperUri = "welcome.jpg"
} else if !strings.Contains(c.options.WallpaperUri, ".") {
c.options.WallpaperUri += fs.ExtJPEG
}
// Valid URI? Local file?
if p := clean.Path(c.options.WallpaperUri); p == "" {
c.options.WallpaperUri = ""
} else if fs.FileExists(path.Join(c.StaticPath(), assetPath, p)) {
c.options.WallpaperUri = path.Join(c.StaticUri(), assetPath, p)
} else if fs.FileExists(c.CustomStaticFile(path.Join(assetPath, p))) {
c.options.WallpaperUri = path.Join(c.CustomStaticUri(), assetPath, p)
} else {
c.options.WallpaperUri = ""
}
return c.options.WallpaperUri
}