diff --git a/src/app/command/config-defaults.go b/src/app/command/config-defaults.go index c822b12..8ca9c30 100644 --- a/src/app/command/config-defaults.go +++ b/src/app/command/config-defaults.go @@ -92,10 +92,13 @@ func init() { NoProgramRetries: defaultNoProgramRetries, Labels: MsLabelsConfig{ Adhoc: "ADHOC", - Journal: ".journal.txt", + Journal: ".journal", Legacy: ".LEGACY", Trash: "TRASH", }, + Extensions: MsExtensionsConfig{ + Suffixes: "jpg,jpeg,png", + }, } userHomeDir, err := os.UserHomeDir() diff --git a/src/app/command/ms-config.go b/src/app/command/ms-config.go index 6507dbc..befaf47 100644 --- a/src/app/command/ms-config.go +++ b/src/app/command/ms-config.go @@ -77,11 +77,16 @@ type MsLabelsConfig struct { Trash string `mapstructure:"trash"` } +type MsExtensionsConfig struct { + Suffixes string `mapstructure:"suffixes"` +} + type MsAdvancedConfig struct { - Abort bool `mapstructure:"abort-on-error"` - Timeout string `mapstructure:"program-timeout"` - NoProgramRetries uint `mapstructure:"no-program-retries"` - Labels MsLabelsConfig `mapstructure:"labels"` + Abort bool `mapstructure:"abort-on-error"` + Timeout string `mapstructure:"program-timeout"` + NoProgramRetries uint `mapstructure:"no-program-retries"` + Labels MsLabelsConfig `mapstructure:"labels"` + Extensions MsExtensionsConfig `mapstructure:"extensions"` } func (cfg *MsAdvancedConfig) AbortOnError() bool { @@ -112,6 +117,10 @@ func (cfg *MsAdvancedConfig) TrashLabel() string { return cfg.Labels.Trash } +func (cfg *MsAdvancedConfig) Suffixes() string { + return cfg.Extensions.Suffixes +} + type MsLoggingConfig struct { LogPath string `mapstructure:"log-path"` MaxSize uint `mapstructure:"max-size"` diff --git a/src/app/mocks/mocks-config.go b/src/app/mocks/mocks-config.go index 518c516..ac250fd 100644 --- a/src/app/mocks/mocks-config.go +++ b/src/app/mocks/mocks-config.go @@ -418,6 +418,20 @@ func (mr *MockAdvancedConfigMockRecorder) ProgramTimeout() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "ProgramTimeout", reflect.TypeOf((*MockAdvancedConfig)(nil).ProgramTimeout)) } +// Suffixes mocks base method. +func (m *MockAdvancedConfig) Suffixes() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Suffixes") + ret0, _ := ret[0].(string) + return ret0 +} + +// Suffixes indicates an expected call of Suffixes. +func (mr *MockAdvancedConfigMockRecorder) Suffixes() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Suffixes", reflect.TypeOf((*MockAdvancedConfig)(nil).Suffixes)) +} + // TrashLabel mocks base method. func (m *MockAdvancedConfig) TrashLabel() string { m.ctrl.T.Helper() @@ -493,6 +507,20 @@ func (m *MockLoggingConfig) EXPECT() *MockLoggingConfigMockRecorder { return m.recorder } +// Level mocks base method. +func (m *MockLoggingConfig) Level() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "Level") + ret0, _ := ret[0].(string) + return ret0 +} + +// Level indicates an expected call of Level. +func (mr *MockLoggingConfigMockRecorder) Level() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Level", reflect.TypeOf((*MockLoggingConfig)(nil).Level)) +} + // MaxAgeInDays mocks base method. func (m *MockLoggingConfig) MaxAgeInDays() uint { m.ctrl.T.Helper() @@ -549,6 +577,20 @@ func (mr *MockLoggingConfigMockRecorder) Path() *gomock.Call { return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Path", reflect.TypeOf((*MockLoggingConfig)(nil).Path)) } +// TimeFormat mocks base method. +func (m *MockLoggingConfig) TimeFormat() string { + m.ctrl.T.Helper() + ret := m.ctrl.Call(m, "TimeFormat") + ret0, _ := ret[0].(string) + return ret0 +} + +// TimeFormat indicates an expected call of TimeFormat. +func (mr *MockLoggingConfigMockRecorder) TimeFormat() *gomock.Call { + mr.mock.ctrl.T.Helper() + return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "TimeFormat", reflect.TypeOf((*MockLoggingConfig)(nil).TimeFormat)) +} + // MockLoggingConfigReader is a mock of LoggingConfigReader interface. type MockLoggingConfigReader struct { ctrl *gomock.Controller diff --git a/src/app/proxy/config.go b/src/app/proxy/config.go index 9ef4280..078a9e5 100644 --- a/src/app/proxy/config.go +++ b/src/app/proxy/config.go @@ -48,6 +48,7 @@ type ( JournalLabel() string LegacyLabel() string TrashLabel() string + Suffixes() string } AdvancedConfigReader interface { diff --git a/src/app/proxy/enter-shrink.go b/src/app/proxy/enter-shrink.go index d844871..2905b26 100644 --- a/src/app/proxy/enter-shrink.go +++ b/src/app/proxy/enter-shrink.go @@ -51,18 +51,12 @@ func (e *ShrinkEntry) getFilterDefs() *nav.FilterDefinitions { defs *nav.FilterDefinitions folderDefined = true pattern string + suffixes = e.AdvancedCFG.Suffixes() ) - const ( - defaultGbSuffix = "*.jp*g" - defaultRxSuffix = "(?i).(jpe?g|png)$" - ) - - extensions := "jpg,jpeg,png" - switch { case e.Inputs.PolyFam.Native.Files != "": - pattern = fmt.Sprintf("%v|%v", e.Inputs.PolyFam.Native.Files, extensions) + pattern = fmt.Sprintf("%v|%v", e.Inputs.PolyFam.Native.Files, suffixes) file = &nav.FilterDef{ Type: nav.FilterTypeExtendedGlobEn, @@ -87,7 +81,7 @@ func (e *ShrinkEntry) getFilterDefs() *nav.FilterDefinitions { } default: - pattern = fmt.Sprintf("*|%v", extensions) + pattern = fmt.Sprintf("*|%v", suffixes) file = &nav.FilterDef{ Type: nav.FilterTypeExtendedGlobEn, Description: fmt.Sprintf("default extended glob filter: '%v'", pattern), @@ -197,6 +191,10 @@ func (e *ShrinkEntry) createFinder() *PathFinder { trash: e.AdvancedCFG.TrashLabel(), } + if !strings.HasSuffix(finder.statics.journal, ".txt") { + finder.statics.journal += ".txt" + } + return finder } diff --git a/src/internal/helpers/mock-config-data.go b/src/internal/helpers/mock-config-data.go index c6cd747..4bc9227 100644 --- a/src/internal/helpers/mock-config-data.go +++ b/src/internal/helpers/mock-config-data.go @@ -111,11 +111,15 @@ type testLabelsConfig struct { Trash string } +type testExtensionsConfig struct { + Suffixes string +} type testAdvancedConfig struct { Abort bool Timeout string NoProgramRetries uint Labels testLabelsConfig + Extensions testExtensionsConfig } func (cfg *testAdvancedConfig) AbortOnError() bool { @@ -146,6 +150,10 @@ func (cfg *testAdvancedConfig) TrashLabel() string { return cfg.Labels.Trash } +func (cfg *testAdvancedConfig) Suffixes() string { + return cfg.Extensions.Suffixes +} + type testLoggingConfig struct { LogPath string MaxSize uint @@ -262,6 +270,9 @@ func init() { Legacy: ".LEGACY", Trash: "TRASH", }, + Extensions: testExtensionsConfig{ + Suffixes: "jpg,jpeg,png", + }, } LoggingConfigData = &testLoggingConfig{ diff --git a/test/data/configuration/pixa-test.yml b/test/data/configuration/pixa-test.yml index a1b502f..1c25e19 100644 --- a/test/data/configuration/pixa-test.yml +++ b/test/data/configuration/pixa-test.yml @@ -34,7 +34,7 @@ advanced: journal-suffix: .journal.txt trash: TRASH extensions: - suffixes: "jpg,png" + suffixes: "jpg,jpeg,png" logging: log-path: "~/snivilised/pixa/pixa.log" max-size: 10