From 3b9890e345567a0ed57a065cd2e1215bde6c9ffc Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Tue, 25 Oct 2022 06:19:56 +0200 Subject: [PATCH] Config: Update options report, parameter names and tests Signed-off-by: Michael Mayer --- internal/commands/show_options.go | 2 +- internal/config/config_auth.go | 24 ++++++++--------- internal/config/config_auth_test.go | 20 +++++++-------- internal/config/config_const.go | 8 +++--- internal/config/config_tls_test.go | 4 +-- internal/config/flags.go | 30 +++++++++++----------- internal/config/options.go | 6 ++--- internal/config/report.go | 6 ++--- internal/meta/exif_parser.go | 2 +- internal/meta/exif_test.go | 2 +- internal/photoprism/mediafile.go | 4 +-- internal/photoprism/mediafile_meta_test.go | 2 +- internal/photoprism/mediafile_test.go | 4 +-- internal/photoprism/related_test.go | 2 +- internal/query/file_selection.go | 2 +- internal/session/session_new.go | 2 +- pkg/fs/file_exts.go | 14 +++++----- pkg/fs/file_types.go | 3 ++- pkg/fs/file_types_info.go | 1 + pkg/media/formats.go | 2 +- 20 files changed, 71 insertions(+), 69 deletions(-) diff --git a/internal/commands/show_options.go b/internal/commands/show_options.go index 9e4086097..3438e1604 100644 --- a/internal/commands/show_options.go +++ b/internal/commands/show_options.go @@ -54,7 +54,7 @@ func showOptionsAction(ctx *cli.Context) error { {Start: "PHOTOPRISM_READONLY", Title: "Feature Flags"}, {Start: "PHOTOPRISM_DEFAULT_LOCALE", Title: "Customization"}, {Start: "PHOTOPRISM_CDN_URL", Title: "Site Information"}, - {Start: "PHOTOPRISM_HTTP_PORT", Title: "Web Server"}, + {Start: "PHOTOPRISM_TRUSTED_PROXY", Title: "Web Server"}, {Start: "PHOTOPRISM_DATABASE_DRIVER", Title: "Database Connection"}, {Start: "PHOTOPRISM_DARKTABLE_BIN", Title: "File Converters"}, {Start: "PHOTOPRISM_DOWNLOAD_TOKEN", Title: "Security Tokens"}, diff --git a/internal/config/config_auth.go b/internal/config/config_auth.go index eeb83b3ee..1399e1e7a 100644 --- a/internal/config/config_auth.go +++ b/internal/config/config_auth.go @@ -40,26 +40,26 @@ func (c *Config) AdminPassword() string { return clean.Password(c.options.AdminPassword) } -// SessMaxAge returns the time in seconds until browser sessions expire automatically. -func (c *Config) SessMaxAge() int64 { - if c.options.SessMaxAge < 0 { +// SessionMaxAge returns the time in seconds until API sessions expire automatically. +func (c *Config) SessionMaxAge() int64 { + if c.options.SessionMaxAge < 0 { return 0 - } else if c.options.SessMaxAge == 0 { - return DefaultSessMaxAge + } else if c.options.SessionMaxAge == 0 { + return DefaultSessionMaxAge } - return c.options.SessMaxAge + return c.options.SessionMaxAge } -// SessTimeout returns the time in seconds until browser sessions expire due to inactivity -func (c *Config) SessTimeout() int64 { - if c.options.SessTimeout < 0 { +// SessionTimeout returns the time in seconds until API sessions expire due to inactivity +func (c *Config) SessionTimeout() int64 { + if c.options.SessionTimeout < 0 { return 0 - } else if c.options.SessTimeout == 0 { - return DefaultSessTimeout + } else if c.options.SessionTimeout == 0 { + return DefaultSessionTimeout } - return c.options.SessTimeout + return c.options.SessionTimeout } // Public checks if app runs in public mode and requires no authentication. diff --git a/internal/config/config_auth_test.go b/internal/config/config_auth_test.go index 49bb98390..0eb2a52dc 100644 --- a/internal/config/config_auth_test.go +++ b/internal/config/config_auth_test.go @@ -48,20 +48,20 @@ func TestAuth(t *testing.T) { func TestSessMaxAge(t *testing.T) { c := NewConfig(CliTestContext()) - assert.Equal(t, DefaultSessMaxAge, c.SessMaxAge()) - c.options.SessMaxAge = -1 - assert.Equal(t, int64(0), c.SessMaxAge()) - c.options.SessMaxAge = 0 - assert.Equal(t, DefaultSessMaxAge, c.SessMaxAge()) + assert.Equal(t, DefaultSessionMaxAge, c.SessionMaxAge()) + c.options.SessionMaxAge = -1 + assert.Equal(t, int64(0), c.SessionMaxAge()) + c.options.SessionMaxAge = 0 + assert.Equal(t, DefaultSessionMaxAge, c.SessionMaxAge()) } func TestSessTimeout(t *testing.T) { c := NewConfig(CliTestContext()) - assert.Equal(t, DefaultSessTimeout, c.SessTimeout()) - c.options.SessTimeout = -1 - assert.Equal(t, int64(0), c.SessTimeout()) - c.options.SessTimeout = 0 - assert.Equal(t, DefaultSessTimeout, c.SessTimeout()) + assert.Equal(t, DefaultSessionTimeout, c.SessionTimeout()) + c.options.SessionTimeout = -1 + assert.Equal(t, int64(0), c.SessionTimeout()) + c.options.SessionTimeout = 0 + assert.Equal(t, DefaultSessionTimeout, c.SessionTimeout()) } func TestUtils_CheckPassword(t *testing.T) { diff --git a/internal/config/config_const.go b/internal/config/config_const.go index 3ebc76955..d95ae5287 100644 --- a/internal/config/config_const.go +++ b/internal/config/config_const.go @@ -58,8 +58,8 @@ const UnixDay = UnixHour * 24 // UnixWeek is one week in UnixTime. const UnixWeek = UnixDay * 7 -// DefaultSessMaxAge is the default session expiration time in seconds. -const DefaultSessMaxAge = UnixWeek * 2 +// DefaultSessionMaxAge is the default session expiration time in seconds. +const DefaultSessionMaxAge = UnixWeek * 2 -// DefaultSessTimeout is the default session timeout time in seconds. -const DefaultSessTimeout = UnixWeek +// DefaultSessionTimeout is the default session timeout time in seconds. +const DefaultSessionTimeout = UnixWeek diff --git a/internal/config/config_tls_test.go b/internal/config/config_tls_test.go index 49b7bb8e5..1ebf192e5 100644 --- a/internal/config/config_tls_test.go +++ b/internal/config/config_tls_test.go @@ -31,13 +31,13 @@ func TestConfig_TLSEmail(t *testing.T) { func TestConfig_TLSCert(t *testing.T) { c := NewConfig(CliTestContext()) - assert.Equal(t, "/etc/ssl/certs/photoprism.me.crt", c.TLSCert()) + assert.True(t, strings.HasSuffix(c.TLSCert(), "photoprism.me.crt")) } func TestConfig_TLSKey(t *testing.T) { c := NewConfig(CliTestContext()) - assert.Equal(t, "/etc/ssl/private/photoprism.me.key", c.TLSKey()) + assert.True(t, strings.HasSuffix(c.TLSKey(), "photoprism.me.key")) } func TestConfig_TLS(t *testing.T) { diff --git a/internal/config/flags.go b/internal/config/flags.go index 2cda7ab0c..c3734b1ad 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -37,16 +37,16 @@ var Flags = CliFlags{ EnvVar: "PHOTOPRISM_ADMIN_PASSWORD", }}, { Flag: cli.Int64Flag{ - Name: "sess-maxage", - Value: DefaultSessMaxAge, - Usage: "time in `SECONDS` until user sessions expire automatically (-1 to disable)", - EnvVar: "PHOTOPRISM_SESS_MAXAGE", + Name: "session-maxage", + Value: DefaultSessionMaxAge, + Usage: "time in `SECONDS` until API sessions expire automatically (-1 to disable)", + EnvVar: "PHOTOPRISM_SESSION_MAXAGE", }}, { Flag: cli.Int64Flag{ - Name: "sess-timeout", - Value: DefaultSessTimeout, - Usage: "time in `SECONDS` until user sessions expire due to inactivity (-1 to disable)", - EnvVar: "PHOTOPRISM_SESS_TIMEOUT", + Name: "session-timeout", + Value: DefaultSessionTimeout, + Usage: "time in `SECONDS` until API sessions expire due to inactivity (-1 to disable)", + EnvVar: "PHOTOPRISM_SESSION_TIMEOUT", }}, { Flag: cli.StringFlag{ Name: "log-level, l", @@ -209,11 +209,6 @@ var Flags = CliFlags{ Usage: "enable experimental features", EnvVar: "PHOTOPRISM_EXPERIMENTAL", }}, { - Flag: cli.BoolFlag{ - Name: "disable-tls", - Usage: "disable HTTPS even if a certificate is available", - EnvVar: "PHOTOPRISM_DISABLE_TLS", - }}, { Flag: cli.BoolFlag{ Name: "disable-webdav", Usage: "disable built-in WebDAV server", @@ -451,6 +446,11 @@ var Flags = CliFlags{ Usage: "Web server port `NUMBER`", EnvVar: "PHOTOPRISM_HTTP_PORT", }}, { + Flag: cli.BoolFlag{ + Name: "disable-tls", + Usage: "disable HTTPS even if a certificate is available", + EnvVar: "PHOTOPRISM_DISABLE_TLS", + }}, { Flag: cli.StringFlag{ Name: "database-driver, db", Usage: "database `DRIVER` (sqlite, mysql)", @@ -575,12 +575,12 @@ var Flags = CliFlags{ }}, { Flag: cli.StringFlag{ Name: "download-token", - Usage: "`SECRET` download URL token for originals (default: random)", + Usage: "`DEFAULT` download URL token for originals (leave empty for a random value)", EnvVar: "PHOTOPRISM_DOWNLOAD_TOKEN", }}, { Flag: cli.StringFlag{ Name: "preview-token", - Usage: "`SECRET` thumbnail and video streaming URL token (default: random)", + Usage: "`DEFAULT` thumbnail and video streaming URL token (leave empty for a random value)", EnvVar: "PHOTOPRISM_PREVIEW_TOKEN", }}, { Flag: cli.StringFlag{ diff --git a/internal/config/options.go b/internal/config/options.go index 51ab71983..19c8c5c8e 100644 --- a/internal/config/options.go +++ b/internal/config/options.go @@ -26,8 +26,8 @@ type Options struct { Public bool `yaml:"Public" json:"-" flag:"public"` AdminUser string `yaml:"AdminUser" json:"-" flag:"admin-user"` AdminPassword string `yaml:"AdminPassword" json:"-" flag:"admin-password"` - SessMaxAge int64 `yaml:"SessMaxAge" json:"-" flag:"sess-maxage"` - SessTimeout int64 `yaml:"SessTimeout" json:"-" flag:"sess-timeout"` + SessionMaxAge int64 `yaml:"SessionMaxAge" json:"-" flag:"session-maxage"` + SessionTimeout int64 `yaml:"SessionTimeout" json:"-" flag:"session-timeout"` LogLevel string `yaml:"LogLevel" json:"-" flag:"log-level"` Prod bool `yaml:"Prod" json:"Prod" flag:"prod"` Debug bool `yaml:"Debug" json:"Debug" flag:"debug"` @@ -97,10 +97,10 @@ type Options struct { HttpCompression string `yaml:"HttpCompression" json:"-" flag:"http-compression"` HttpHost string `yaml:"HttpHost" json:"-" flag:"http-host"` HttpPort int `yaml:"HttpPort" json:"-" flag:"http-port"` + DisableTLS bool `yaml:"DisableTLS" json:"DisableTLS" flag:"disable-tls"` TLSEmail string `yaml:"TLSEmail" json:"TLSEmail" flag:"tls-email"` // TLSEmail enabled automatic HTTPS via Let's Encrypt if set a valid email address. TLSCert string `yaml:"TLSCert" json:"TLSCert" flag:"tls-cert"` TLSKey string `yaml:"TLSKey" json:"TLSKey" flag:"tls-key"` - DisableTLS bool `yaml:"DisableTLS" json:"DisableTLS" flag:"disable-tls"` DatabaseDriver string `yaml:"DatabaseDriver" json:"-" flag:"database-driver"` DatabaseDsn string `yaml:"DatabaseDsn" json:"-" flag:"database-dsn"` DatabaseName string `yaml:"DatabaseName" json:"-" flag:"database-name"` diff --git a/internal/config/report.go b/internal/config/report.go index c374a455b..3cc5bcf74 100644 --- a/internal/config/report.go +++ b/internal/config/report.go @@ -25,8 +25,8 @@ func (c *Config) Report() (rows [][]string, cols []string) { {"admin-user", c.AdminUser()}, {"admin-password", strings.Repeat("*", utf8.RuneCountInString(c.AdminPassword()))}, {"public", fmt.Sprintf("%t", c.Public())}, - {"sess-maxage", fmt.Sprintf("%d", c.SessMaxAge())}, - {"sess-timeout", fmt.Sprintf("%d", c.SessTimeout())}, + {"session-maxage", fmt.Sprintf("%d", c.SessionMaxAge())}, + {"session-timeout", fmt.Sprintf("%d", c.SessionTimeout())}, // Logging. {"log-level", c.LogLevel().String()}, @@ -72,7 +72,6 @@ func (c *Config) Report() (rows [][]string, cols []string) { // Feature Flags. {"read-only", fmt.Sprintf("%t", c.ReadOnly())}, {"experimental", fmt.Sprintf("%t", c.Experimental())}, - {"disable-tls", fmt.Sprintf("%t", c.DisableTLS())}, {"disable-webdav", fmt.Sprintf("%t", c.DisableWebDAV())}, {"disable-settings", fmt.Sprintf("%t", c.DisableSettings())}, {"disable-places", fmt.Sprintf("%t", c.DisablePlaces())}, @@ -137,6 +136,7 @@ func (c *Config) Report() (rows [][]string, cols []string) { {"http-compression", c.HttpCompression()}, {"http-host", c.HttpHost()}, {"http-port", fmt.Sprintf("%d", c.HttpPort())}, + {"disable-tls", fmt.Sprintf("%t", c.DisableTLS())}, {"tls-email", c.TLSEmail()}, {"tls-cert", c.TLSCert()}, {"tls-key", c.TLSKey()}, diff --git a/internal/meta/exif_parser.go b/internal/meta/exif_parser.go index 72223f680..89d81cbd0 100644 --- a/internal/meta/exif_parser.go +++ b/internal/meta/exif_parser.go @@ -73,7 +73,7 @@ func RawExif(fileName string, fileFormat fs.Type, bruteForce bool) (rawExif []by parsed = true } } - case fs.ImageHEIF: + case fs.ImageHEIC: heicMp := heicexif.NewHeicExifMediaParser() cs, err := heicMp.ParseFile(fileName) diff --git a/internal/meta/exif_test.go b/internal/meta/exif_test.go index 9fed26b92..bfcee7196 100644 --- a/internal/meta/exif_test.go +++ b/internal/meta/exif_test.go @@ -172,7 +172,7 @@ func TestExif(t *testing.T) { }) t.Run("iphone_7.heic", func(t *testing.T) { - data, err := Exif("testdata/iphone_7.heic", fs.ImageHEIF, true) + data, err := Exif("testdata/iphone_7.heic", fs.ImageHEIC, true) if err != nil { t.Fatal(err) } diff --git a/internal/photoprism/mediafile.go b/internal/photoprism/mediafile.go index 2dac6df3f..f9c844913 100644 --- a/internal/photoprism/mediafile.go +++ b/internal/photoprism/mediafile.go @@ -794,7 +794,7 @@ func (m *MediaFile) FileType() fs.Type { case m.IsAVIF(): return fs.ImageAVIF case m.IsHEIC(): - return fs.ImageHEIF + return fs.ImageHEIC default: return fs.FileType(m.fileName) } @@ -871,7 +871,7 @@ func (m *MediaFile) IsLive() bool { } if m.IsVideo() { - return fs.ImageHEIF.FindFirst(m.FileName(), []string{}, Config().OriginalsPath(), false) != "" + return fs.ImageHEIC.FindFirst(m.FileName(), []string{}, Config().OriginalsPath(), false) != "" } return false diff --git a/internal/photoprism/mediafile_meta_test.go b/internal/photoprism/mediafile_meta_test.go index 58fd2bc1c..75b2b723f 100644 --- a/internal/photoprism/mediafile_meta_test.go +++ b/internal/photoprism/mediafile_meta_test.go @@ -317,7 +317,7 @@ func TestMediaFile_Exif_DNG(t *testing.T) { assert.NotEmpty(t, info.Height) } -func TestMediaFile_Exif_HEIF(t *testing.T) { +func TestMediaFile_Exif_HEIC(t *testing.T) { if testing.Short() { t.Skip("skipping test in short mode.") } diff --git a/internal/photoprism/mediafile_test.go b/internal/photoprism/mediafile_test.go index 2c7a90a41..c38d0e252 100644 --- a/internal/photoprism/mediafile_test.go +++ b/internal/photoprism/mediafile_test.go @@ -1113,7 +1113,7 @@ func TestMediaFile_HasType(t *testing.T) { if err != nil { t.Fatal(err) } - assert.Equal(t, true, mediaFile.HasFileType("heif")) + assert.Equal(t, true, mediaFile.HasFileType("heic")) }) t.Run("iphone_7.xmp", func(t *testing.T) { mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/iphone_7.xmp") @@ -1124,7 +1124,7 @@ func TestMediaFile_HasType(t *testing.T) { }) } -func TestMediaFile_IsHEIF(t *testing.T) { +func TestMediaFile_IsHEIC(t *testing.T) { conf := config.TestConfig() t.Run("iphone_7.json", func(t *testing.T) { diff --git a/internal/photoprism/related_test.go b/internal/photoprism/related_test.go index 8eba74609..3443f5df0 100644 --- a/internal/photoprism/related_test.go +++ b/internal/photoprism/related_test.go @@ -175,7 +175,7 @@ func TestRelatedFiles_MainFileType(t *testing.T) { Files: MediaFiles{mediaFile, mediaFile2}, Main: mediaFile3, } - assert.Equal(t, string(fs.ImageHEIF), relatedFiles.MainFileType()) + assert.Equal(t, string(fs.ImageHEIC), relatedFiles.MainFileType()) }) } diff --git a/internal/query/file_selection.go b/internal/query/file_selection.go index bf80bed55..962d395dd 100644 --- a/internal/query/file_selection.go +++ b/internal/query/file_selection.go @@ -66,7 +66,7 @@ func ShareSelection(originals bool) FileSelection { fs.ImageWebP.String(), fs.ImageTIFF.String(), fs.ImageAVIF.String(), - fs.ImageHEIF.String(), + fs.ImageHEIC.String(), fs.ImageBMP.String(), fs.ImageGIF.String(), } diff --git a/internal/session/session_new.go b/internal/session/session_new.go index 82f6a633f..7003437f2 100644 --- a/internal/session/session_new.go +++ b/internal/session/session_new.go @@ -8,5 +8,5 @@ import ( // New creates a session with a context if it is specified. func (s *Session) New(c *gin.Context) (m *entity.Session) { - return entity.NewSession(s.conf.SessMaxAge(), s.conf.SessTimeout()).SetContext(c) + return entity.NewSession(s.conf.SessionMaxAge(), s.conf.SessionTimeout()).SetContext(c) } diff --git a/pkg/fs/file_exts.go b/pkg/fs/file_exts.go index d90c35ee6..2f8681e68 100644 --- a/pkg/fs/file_exts.go +++ b/pkg/fs/file_exts.go @@ -26,13 +26,13 @@ var Extensions = FileExtensions{ ".dng": ImageDNG, ".avif": ImageAVIF, ".avifs": ImageAVIF, - ".heif": ImageHEIF, - ".hif": ImageHEIF, - ".heic": ImageHEIF, - ".heifs": ImageHEIF, - ".heics": ImageHEIF, - ".avci": ImageHEIF, - ".avcs": ImageHEIF, + ".heif": ImageHEIC, + ".hif": ImageHEIC, + ".heic": ImageHEIC, + ".heifs": ImageHEIC, + ".heics": ImageHEIC, + ".avci": ImageHEIC, + ".avcs": ImageHEIC, ".webp": ImageWebP, ".mpo": ImageMPO, ".3fr": ImageRaw, diff --git a/pkg/fs/file_types.go b/pkg/fs/file_types.go index 3e9fdade4..1f1151ac2 100644 --- a/pkg/fs/file_types.go +++ b/pkg/fs/file_types.go @@ -19,7 +19,8 @@ const ( ImageTIFF Type = "tiff" // TIFF image ImageDNG Type = "dng" // Adobe Digital Negative image ImageAVIF Type = "avif" // AV1 Image File Format (AVIF) - ImageHEIF Type = "heif" // High Efficiency Image File Format (HEIF/HEIC) + ImageHEIF Type = "heif" // High Efficiency Image File Format (HEIF) + ImageHEIC Type = "heic" // High Efficiency Image Container (HEIC) ImageBMP Type = "bmp" // BMP image ImageMPO Type = "mpo" // Stereoscopic Image that consists of two JPG images that are combined into one 3D image ImageWebP Type = "webp" // Google WebP Image diff --git a/pkg/fs/file_types_info.go b/pkg/fs/file_types_info.go index 823a39541..8b881bff6 100644 --- a/pkg/fs/file_types_info.go +++ b/pkg/fs/file_types_info.go @@ -12,6 +12,7 @@ var TypeInfo = map[Type]string{ ImageMPO: "Stereoscopic JPEG (3D)", ImageAVIF: "AV1 Image File Format", ImageHEIF: "High Efficiency Image File Format", + ImageHEIC: "High Efficiency Image Container", ImageWebP: "Google WebP", VideoWebM: "Google WebM", VideoMP2: "MPEG 2 (H.262)", diff --git a/pkg/media/formats.go b/pkg/media/formats.go index 206bdf8d5..db16995c9 100644 --- a/pkg/media/formats.go +++ b/pkg/media/formats.go @@ -13,7 +13,7 @@ var Formats = map[fs.Type]Type{ fs.ImageBMP: Image, fs.ImageMPO: Image, fs.ImageAVIF: Image, - fs.ImageHEIF: Image, + fs.ImageHEIC: Image, fs.VideoHEVC: Video, fs.ImageWebP: Image, fs.VideoWebM: Video,