From 2b48052e6d4bde8b8735b6e0bcbb70b6c5780510 Mon Sep 17 00:00:00 2001 From: BeziCZ Date: Sun, 11 May 2025 16:23:43 +0200 Subject: [PATCH] Fix importing old db --- settings/settings.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/settings/settings.go b/settings/settings.go index e2eb25df..27cdff58 100644 --- a/settings/settings.go +++ b/settings/settings.go @@ -2,6 +2,8 @@ package settings import ( "crypto/rand" + "encoding/json" + "fmt" "log" "strings" "time" @@ -81,3 +83,40 @@ func GenerateKey() ([]byte, error) { return b, nil } + +// UnmarshalJSON implements custom JSON unmarshaling for Settings +func (s *Settings) UnmarshalJSON(data []byte) error { + + type Alias Settings + aux := &struct { + Shell interface{} `json:"shell"` + *Alias + }{ + Alias: (*Alias)(s), + } + + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + + // Handle the Shell field conversion + switch v := aux.Shell.(type) { + case string: + s.Shell = v + case []interface{}: + // Convert array to string by joining elements + var parts []string + for _, item := range v { + if str, ok := item.(string); ok { + parts = append(parts, str) + } + } + s.Shell = strings.Join(parts, " ") + case nil: + s.Shell = "" + default: + return fmt.Errorf("invalid type for shell field: %T", v) + } + + return nil +}