Fix importing old db

pull/3899/head
BeziCZ 2025-05-11 16:23:43 +02:00
parent 3aa10e1861
commit 2b48052e6d
1 changed files with 39 additions and 0 deletions

View File

@ -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
}