chore: migrate mail themes to shared framework and locked upstream inputs
This commit is contained in:
1 parent
5c0589f6f6
commit
fec3ace600
225 files changed
+4718
-15807
No files matched your search
+31
-2
@@ -12,7 +12,7 @@ import (
|
||||
type TemplateConfig struct {
|
||||
Name string `json:"name"`
|
||||
Desc string `json:"desc"`
|
||||
Path []string `json:"path"`
|
||||
Path []string `json:"-"` // Discovered from the pinned upstream snapshot.
|
||||
Params map[string]any `json:"params"`
|
||||
}
|
||||
|
||||
@@ -29,7 +29,9 @@ func Load(path string) (*TemplatesConfig, error) {
|
||||
}
|
||||
|
||||
var cfg TemplatesConfig
|
||||
if err := json.Unmarshal(data, &cfg); err != nil {
|
||||
decoder := json.NewDecoder(strings.NewReader(string(data)))
|
||||
decoder.UseNumber()
|
||||
if err := decoder.Decode(&cfg); err != nil {
|
||||
return nil, fmt.Errorf("cannot parse config file %s: %w", path, err)
|
||||
}
|
||||
|
||||
@@ -37,9 +39,36 @@ func Load(path string) (*TemplatesConfig, error) {
|
||||
return nil, fmt.Errorf("config file %s contains no template definitions", path)
|
||||
}
|
||||
|
||||
for id, t := range cfg.Templates {
|
||||
t.Params = normalizeNumbers(t.Params).(map[string]any)
|
||||
cfg.Templates[id] = t
|
||||
}
|
||||
return &cfg, nil
|
||||
}
|
||||
|
||||
func normalizeNumbers(v any) any {
|
||||
switch v := v.(type) {
|
||||
case json.Number:
|
||||
if n, err := v.Int64(); err == nil {
|
||||
return n
|
||||
}
|
||||
n, _ := v.Float64()
|
||||
return n
|
||||
case map[string]any:
|
||||
for k, value := range v {
|
||||
v[k] = normalizeNumbers(value)
|
||||
}
|
||||
return v
|
||||
case []any:
|
||||
for i, value := range v {
|
||||
v[i] = normalizeNumbers(value)
|
||||
}
|
||||
return v
|
||||
default:
|
||||
return v
|
||||
}
|
||||
}
|
||||
|
||||
// PathStr returns the file path of a template definition joined with OS separator.
|
||||
func (t *TemplateConfig) PathStr() string {
|
||||
return filepath.Join(t.Path...)
|
||||
|
||||
Reference in new issue
Block a user