MCPcopy Index your code
hub / github.com/aiprodcoder/MIXAPI / MigrateConsoleSetting

Function MigrateConsoleSetting

controller/console_migrate.go:14–103  ·  view source on GitHub ↗

MigrateConsoleSetting 迁移旧的控制台相关配置到 console_setting.*

(c *gin.Context)

Source from the content-addressed store, hash-verified

12
13// MigrateConsoleSetting 迁移旧的控制台相关配置到 console_setting.*
14func MigrateConsoleSetting(c *gin.Context) {
15 // 读取全部 option
16 opts, err := model.AllOption()
17 if err != nil {
18 c.JSON(http.StatusInternalServerError, gin.H{"success": false, "message": err.Error()})
19 return
20 }
21 // 建立 map
22 valMap := map[string]string{}
23 for _, o := range opts {
24 valMap[o.Key] = o.Value
25 }
26
27 // 处理 APIInfo
28 if v := valMap["ApiInfo"]; v != "" {
29 var arr []map[string]interface{}
30 if err := json.Unmarshal([]byte(v), &arr); err == nil {
31 if len(arr) > 50 {
32 arr = arr[:50]
33 }
34 bytes, _ := json.Marshal(arr)
35 model.UpdateOption("console_setting.api_info", string(bytes))
36 }
37 model.UpdateOption("ApiInfo", "")
38 }
39 // Announcements 直接搬
40 if v := valMap["Announcements"]; v != "" {
41 model.UpdateOption("console_setting.announcements", v)
42 model.UpdateOption("Announcements", "")
43 }
44 // FAQ 转换
45 if v := valMap["FAQ"]; v != "" {
46 var arr []map[string]interface{}
47 if err := json.Unmarshal([]byte(v), &arr); err == nil {
48 out := []map[string]interface{}{}
49 for _, item := range arr {
50 q, _ := item["question"].(string)
51 if q == "" {
52 q, _ = item["title"].(string)
53 }
54 a, _ := item["answer"].(string)
55 if a == "" {
56 a, _ = item["content"].(string)
57 }
58 if q != "" && a != "" {
59 out = append(out, map[string]interface{}{"question": q, "answer": a})
60 }
61 }
62 if len(out) > 50 {
63 out = out[:50]
64 }
65 bytes, _ := json.Marshal(out)
66 model.UpdateOption("console_setting.faq", string(bytes))
67 }
68 model.UpdateOption("FAQ", "")
69 }
70 // Uptime Kuma 迁移到新的 groups 结构(console_setting.uptime_kuma_groups)
71 url := valMap["UptimeKumaUrl"]

Callers

nothing calls this directly

Calls 6

AllOptionFunction · 0.92
UpdateOptionFunction · 0.92
InitOptionMapFunction · 0.92
SysLogFunction · 0.92
ErrorMethod · 0.80
DeleteMethod · 0.45

Tested by

no test coverage detected