2021-11-22 11:26:10 +01:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
2022-04-22 17:38:40 +02:00
|
|
|
"path"
|
2021-11-22 11:26:10 +01:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2021-11-22 11:36:46 +01:00
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
"github.com/photoprism/photoprism/internal/i18n"
|
2022-04-22 17:38:40 +02:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2022-04-15 09:42:07 +02:00
|
|
|
// DefaultTheme returns the default user interface theme name.
|
|
|
|
func (c *Config) DefaultTheme() string {
|
2022-04-22 17:38:40 +02:00
|
|
|
if c.options.DefaultTheme == "" || c.NoSponsor() {
|
2022-04-15 09:42:07 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2023-03-20 10:28:01 +01:00
|
|
|
// WallpaperUri returns the login screen background image URI.
|
2022-04-22 17:38:40 +02:00
|
|
|
func (c *Config) WallpaperUri() string {
|
2023-03-20 10:28:01 +01:00
|
|
|
if cacheData, ok := Cache.Get(CacheKeyWallpaperUri); ok {
|
|
|
|
// Return cached wallpaper URI.
|
|
|
|
log.Tracef("config: cache hit for %s", CacheKeyWallpaperUri)
|
|
|
|
|
|
|
|
return cacheData.(string)
|
|
|
|
} else if strings.Contains(c.options.WallpaperUri, "/") {
|
2022-04-22 17:38:40 +02:00
|
|
|
return c.options.WallpaperUri
|
|
|
|
}
|
|
|
|
|
2023-03-20 10:28:01 +01:00
|
|
|
wallpaperUri := c.options.WallpaperUri
|
|
|
|
wallpaperPath := "img/wallpaper"
|
2022-04-22 17:38:40 +02:00
|
|
|
|
2023-03-20 10:28:01 +01:00
|
|
|
// Default to "welcome.jpg" if value is empty and file exists.
|
|
|
|
if wallpaperUri == "" {
|
|
|
|
if !fs.PathExists(filepath.Join(c.StaticPath(), wallpaperPath)) {
|
2022-04-22 17:38:40 +02:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2023-03-20 10:28:01 +01:00
|
|
|
wallpaperUri = "welcome.jpg"
|
|
|
|
} else if !strings.Contains(wallpaperUri, ".") {
|
|
|
|
wallpaperUri += fs.ExtJPEG
|
2022-04-22 17:38:40 +02:00
|
|
|
}
|
|
|
|
|
2023-03-20 10:28:01 +01:00
|
|
|
// Complete URI as needed if file path is valid.
|
|
|
|
if fileName := clean.Path(wallpaperUri); fileName == "" {
|
|
|
|
return ""
|
|
|
|
} else if fs.FileExists(path.Join(c.StaticPath(), wallpaperPath, fileName)) {
|
|
|
|
wallpaperUri = c.StaticAssetUri(path.Join(wallpaperPath, fileName))
|
|
|
|
} else if fs.FileExists(c.CustomStaticFile(path.Join(wallpaperPath, fileName))) {
|
|
|
|
wallpaperUri = c.CustomStaticAssetUri(path.Join(wallpaperPath, fileName))
|
2022-04-22 17:38:40 +02:00
|
|
|
} else {
|
2023-03-20 10:28:01 +01:00
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
// Cache wallpaper URI if not empty.
|
|
|
|
if wallpaperUri != "" {
|
|
|
|
Cache.SetDefault(CacheKeyWallpaperUri, wallpaperUri)
|
2022-04-22 17:38:40 +02:00
|
|
|
}
|
|
|
|
|
2023-03-20 10:28:01 +01:00
|
|
|
return wallpaperUri
|
|
|
|
}
|
|
|
|
|
|
|
|
// SetWallpaperUri changes the login screen background image URI.
|
|
|
|
func (c *Config) SetWallpaperUri(uri string) *Config {
|
|
|
|
c.options.WallpaperUri = uri
|
|
|
|
FlushCache()
|
|
|
|
return c
|
2022-04-22 17:38:40 +02:00
|
|
|
}
|