Skip to content

Commit

Permalink
feat(proxy): add suffixes to advanced config (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
plastikfan committed Jan 11, 2024
1 parent f6bdfac commit 0c8ba8a
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 15 deletions.
5 changes: 4 additions & 1 deletion src/app/command/config-defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
17 changes: 13 additions & 4 deletions src/app/command/ms-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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"`
Expand Down
42 changes: 42 additions & 0 deletions src/app/mocks/mocks-config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/app/proxy/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type (
JournalLabel() string
LegacyLabel() string
TrashLabel() string
Suffixes() string
}

AdvancedConfigReader interface {
Expand Down
16 changes: 7 additions & 9 deletions src/app/proxy/enter-shrink.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions src/internal/helpers/mock-config-data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -262,6 +270,9 @@ func init() {
Legacy: ".LEGACY",
Trash: "TRASH",
},
Extensions: testExtensionsConfig{
Suffixes: "jpg,jpeg,png",
},
}

LoggingConfigData = &testLoggingConfig{
Expand Down
2 changes: 1 addition & 1 deletion test/data/configuration/pixa-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0c8ba8a

Please sign in to comment.