summaryrefslogtreecommitdiff
path: root/config
diff options
from:
to:
context:
space:
mode:
Diffstat (limited to 'config')
-rw-r--r--config/config-b2.sample.json (renamed from config/config.json)2
-rw-r--r--config/config-local-unix.sample.json40
-rw-r--r--config/config.go77
3 files changed, 102 insertions, 17 deletions
diff --git a/config/config.json b/config/config-b2.sample.json
index db4ddd4..d3d772e 100644
--- a/config/config.json
+++ b/config/config-b2.sample.json
@@ -41,4 +41,4 @@
}
}
}
-}
+} \ No newline at end of file
diff --git a/config/config-local-unix.sample.json b/config/config-local-unix.sample.json
new file mode 100644
index 0000000..637a05a
--- /dev/null
+++ b/config/config-local-unix.sample.json
@@ -0,0 +1,40 @@
+{
+ "ForceRewrite": false,
+ "MaxConcurrentJobs": 4,
+ "LogLevel": "debug",
+ "Input": {
+ "Storage": {
+ "Type": "local-unix",
+ "Config": {
+ "MaxDepth": 3,
+ "Path": "/tmp/thumbnailing/full/"
+ }
+ },
+ "KnownExtensions": [
+ "jpg",
+ "jpeg",
+ "png"
+ ]
+ },
+ "Converter": {
+ "Type": "webp",
+ "Config": {
+ "Quality": 80,
+ "Size": {
+ "MaxWidth": 800,
+ "MaxHeight": 0
+ }
+ }
+ },
+ "Output": {
+ "Storage": {
+ "Type": "local-unix",
+ "Config": {
+ "Path": "/tmp/thumbnailing/thumbnails/",
+ "DirPermissionMode": "0755",
+ "FilePermissionMode": "0644",
+ "AttributesImplementation": "xattr"
+ }
+ }
+ }
+} \ No newline at end of file
diff --git a/config/config.go b/config/config.go
index 3ca8f84..d2b7072 100644
--- a/config/config.go
+++ b/config/config.go
@@ -19,16 +19,16 @@ type Config struct {
}
type InputConfig struct {
- Storage StorageConfig `json:"Storage" validate:"required"`
- KnownExtensions []string `json:"KnownExtensions" validate:"required,min=0,dive,min=1"`
+ Storage InputStorageConfig `json:"Storage" validate:"required"`
+ KnownExtensions []string `json:"KnownExtensions" validate:"required,min=0,dive,min=1"`
}
-type StorageConfig struct {
- Type string `json:"Type" validate:"required,oneof=b2 local"`
+type InputStorageConfig struct {
+ Type string `json:"Type" validate:"required,oneof=b2 local-unix"`
Config any `json:"Config" validate:"required"`
}
-func (sc *StorageConfig) UnmarshalJSON(data []byte) error {
+func (sc *InputStorageConfig) UnmarshalJSON(data []byte) error {
var tmp struct {
Type string `json:"Type"`
Config json.RawMessage `json:"Config"`
@@ -47,12 +47,49 @@ func (sc *StorageConfig) UnmarshalJSON(data []byte) error {
return fmt.Errorf("unmarshal B2Config: %w", err)
}
sc.Config = &b2Config
- case "local":
- var localConfig LocalConfig
- if err := json.Unmarshal(tmp.Config, &localConfig); err != nil {
- return fmt.Errorf("unmarshal LocalConfig: %w", err)
+ case "local-unix":
+ var localUnixConfig InputLocalUnixConfig
+ if err := json.Unmarshal(tmp.Config, &localUnixConfig); err != nil {
+ return fmt.Errorf("unmarshal LocalUnixConfig: %w", err)
}
- sc.Config = &localConfig
+ sc.Config = &localUnixConfig
+ default:
+ return fmt.Errorf("unsupported storage type: %s", tmp.Type)
+ }
+
+ return nil
+}
+
+type OutputStorageConfig struct {
+ Type string `json:"Type" validate:"required,oneof=b2 local-unix"`
+ Config any `json:"Config" validate:"required"`
+}
+
+func (sc *OutputStorageConfig) UnmarshalJSON(data []byte) error {
+ var tmp struct {
+ Type string `json:"Type"`
+ Config json.RawMessage `json:"Config"`
+ }
+
+ if err := json.Unmarshal(data, &tmp); err != nil {
+ return err
+ }
+
+ sc.Type = tmp.Type
+
+ switch tmp.Type {
+ case "b2":
+ var b2Config B2Config
+ if err := json.Unmarshal(tmp.Config, &b2Config); err != nil {
+ return fmt.Errorf("unmarshal B2Config: %w", err)
+ }
+ sc.Config = &b2Config
+ case "local-unix":
+ var localUnixConfig OutputLocalUnixConfig
+ if err := json.Unmarshal(tmp.Config, &localUnixConfig); err != nil {
+ return fmt.Errorf("unmarshal LocalUnixConfig: %w", err)
+ }
+ sc.Config = &localUnixConfig
default:
return fmt.Errorf("unsupported storage type: %s", tmp.Type)
}
@@ -68,8 +105,20 @@ type B2Config struct {
ApplicationKey string `json:"ApplicationKey"`
}
-type LocalConfig struct {
- Path string `json:"Path" validate:"required,min=1"`
+type InputLocalUnixConfig struct {
+ MaxDepth int `json:"MaxDepth" validate:"required,min=0"`
+ Path string `json:"Path" validate:"required,min=1"`
+}
+
+type OutputConfig struct {
+ Storage OutputStorageConfig `json:"Storage" validate:"required"`
+}
+
+type OutputLocalUnixConfig struct {
+ Path string `json:"Path" validate:"required,min=1"`
+ DirPermissionMode string `json:"DirPermissionMode" validate:"required,min=3"`
+ FilePermissionMode string `json:"FilePermissionMode" validate:"required,min=3"`
+ AttributesImplementation string `json:"AttributesImplementation" validate:"required,oneof=xattr none"`
}
type ConverterConfig struct {
@@ -113,10 +162,6 @@ type SizeConfig struct {
MaxHeight int `json:"MaxHeight" validate:"required,min=0"`
}
-type OutputConfig struct {
- Storage StorageConfig `json:"Storage" validate:"required"`
-}
-
func LoadConfig(path string, config *Config) error {
fileBytes, err := os.ReadFile(path)
if err != nil {