Config: Propagate backend session status
Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
parent
053c339f46
commit
49be9b873e
|
@ -140,6 +140,9 @@ func (c *Config) Options() *Options {
|
||||||
func (c *Config) Propagate() {
|
func (c *Config) Propagate() {
|
||||||
log.SetLevel(c.LogLevel())
|
log.SetLevel(c.LogLevel())
|
||||||
|
|
||||||
|
// Update options.
|
||||||
|
c.Options().Sponsor = c.Hub().Plus() || c.Options().Sponsor
|
||||||
|
|
||||||
// Set thumbnail generation parameters.
|
// Set thumbnail generation parameters.
|
||||||
thumb.StandardRGB = c.ThumbSRGB()
|
thumb.StandardRGB = c.ThumbSRGB()
|
||||||
thumb.SizePrecached = c.ThumbSizePrecached()
|
thumb.SizePrecached = c.ThumbSizePrecached()
|
||||||
|
@ -176,12 +179,6 @@ func (c *Config) Init() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Show funding info?
|
|
||||||
if !c.Sponsor() {
|
|
||||||
log.Info(MsgSponsor)
|
|
||||||
log.Info(MsgSignUp)
|
|
||||||
}
|
|
||||||
|
|
||||||
if insensitive, err := c.CaseInsensitive(); err != nil {
|
if insensitive, err := c.CaseInsensitive(); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if insensitive {
|
} else if insensitive {
|
||||||
|
@ -223,13 +220,16 @@ func (c *Config) Init() error {
|
||||||
|
|
||||||
c.Propagate()
|
c.Propagate()
|
||||||
|
|
||||||
err := c.connectDb()
|
if err := c.connectDb(); err != nil {
|
||||||
|
return err
|
||||||
if err == nil {
|
} else if !c.Sponsor() {
|
||||||
log.Debugf("config: successfully initialized [%s]", time.Since(start))
|
log.Info(MsgSponsor)
|
||||||
|
log.Info(MsgSignUp)
|
||||||
}
|
}
|
||||||
|
|
||||||
return err
|
log.Debugf("config: successfully initialized [%s]", time.Since(start))
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// readSerial reads and returns the current storage serial.
|
// readSerial reads and returns the current storage serial.
|
||||||
|
@ -471,12 +471,12 @@ func (c *Config) Demo() bool {
|
||||||
return c.options.Demo
|
return c.options.Demo
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sponsor reports if you support our mission, see https://photoprism.app/membership.
|
// Sponsor reports if you have chosen to support our mission.
|
||||||
func (c *Config) Sponsor() bool {
|
func (c *Config) Sponsor() bool {
|
||||||
return Sponsor || c.options.Sponsor
|
return Sponsor || c.options.Sponsor
|
||||||
}
|
}
|
||||||
|
|
||||||
// NoSponsor reports if the instance is not operated by a sponsor.
|
// NoSponsor reports if you prefer not to support our mission.
|
||||||
func (c *Config) NoSponsor() bool {
|
func (c *Config) NoSponsor() bool {
|
||||||
return !c.Sponsor() && !c.Demo()
|
return !c.Sponsor() && !c.Demo()
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,16 @@ import (
|
||||||
"github.com/photoprism/photoprism/pkg/fs"
|
"github.com/photoprism/photoprism/pkg/fs"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
StatusUnknown = ""
|
||||||
|
StatusNew = "unregistered"
|
||||||
|
StatusCommunity = "ce"
|
||||||
|
StatusPlus = "plus"
|
||||||
|
StatusDev = "dev"
|
||||||
|
StatusInt = "int"
|
||||||
|
StatusTest = "test"
|
||||||
|
)
|
||||||
|
|
||||||
// Config represents backend api credentials for maps & geodata.
|
// Config represents backend api credentials for maps & geodata.
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Version string `json:"version" yaml:"Version"`
|
Version string `json:"version" yaml:"Version"`
|
||||||
|
@ -68,6 +78,18 @@ func (c *Config) Propagate() {
|
||||||
places.Secret = c.Secret
|
places.Secret = c.Secret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Plus reports if you have a community membership.
|
||||||
|
func (c *Config) Plus() bool {
|
||||||
|
switch c.Status {
|
||||||
|
case StatusUnknown, StatusNew, StatusCommunity:
|
||||||
|
return false
|
||||||
|
case StatusPlus, StatusDev, StatusInt, StatusTest:
|
||||||
|
return len(c.Session) > 0
|
||||||
|
default:
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Sanitize verifies and sanitizes backend api credentials.
|
// Sanitize verifies and sanitizes backend api credentials.
|
||||||
func (c *Config) Sanitize() {
|
func (c *Config) Sanitize() {
|
||||||
c.Key = strings.ToLower(c.Key)
|
c.Key = strings.ToLower(c.Key)
|
||||||
|
|
|
@ -12,3 +12,17 @@ func TestConfig_MapKey(t *testing.T) {
|
||||||
assert.Equal(t, "", c.MapKey())
|
assert.Equal(t, "", c.MapKey())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfig_Plus(t *testing.T) {
|
||||||
|
t.Run("Status", func(t *testing.T) {
|
||||||
|
c := NewConfig("0.0.0", "testdata/new.yml", "zqkunt22r0bewti9", "test", "PhotoPrism/Test", "test")
|
||||||
|
assert.False(t, c.Plus())
|
||||||
|
c.Status = StatusPlus
|
||||||
|
assert.False(t, c.Plus())
|
||||||
|
c.Session = "bde6d0cf514e5456591de5ae09d981056eb88dccf71ba268974bf2cc7b028545e7641c1dfbaa716e4d13f8b0e0d1863e64c16e1f0ac551fc85e1171a87cbda6608cbe330de9e0d5f5b0e14ff61f2ff08fee369"
|
||||||
|
assert.True(t, c.Plus())
|
||||||
|
c.Status = ""
|
||||||
|
assert.False(t, c.Plus())
|
||||||
|
c.Session = ""
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue