MCPcopy
hub / github.com/QuantumNous/new-api / MigrateConsoleSetting

Function MigrateConsoleSetting

controller/console_migrate.go:16–106  ·  view source on GitHub ↗

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

(c *gin.Context)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 9

AllOptionFunction · 0.92
SysErrorFunction · 0.92
UpdateOptionFunction · 0.92
InitOptionMapFunction · 0.92
SysLogFunction · 0.92
UnmarshalMethod · 0.80
MarshalMethod · 0.80
ErrorMethod · 0.45
DeleteMethod · 0.45

Tested by

no test coverage detected