github.com/cloudreve/Cloudreve/v3@v3.0.0-20240224133659-3edb00a6484c/pkg/serializer/setting.go (about) 1 package serializer 2 3 import ( 4 model "github.com/cloudreve/Cloudreve/v3/models" 5 "time" 6 ) 7 8 // SiteConfig 站点全局设置序列 9 type SiteConfig struct { 10 SiteName string `json:"title"` 11 LoginCaptcha bool `json:"loginCaptcha"` 12 RegCaptcha bool `json:"regCaptcha"` 13 ForgetCaptcha bool `json:"forgetCaptcha"` 14 EmailActive bool `json:"emailActive"` 15 Themes string `json:"themes"` 16 DefaultTheme string `json:"defaultTheme"` 17 HomepageViewMethod string `json:"home_view_method"` 18 ShareViewMethod string `json:"share_view_method"` 19 Authn bool `json:"authn"` 20 User User `json:"user"` 21 ReCaptchaKey string `json:"captcha_ReCaptchaKey"` 22 CaptchaType string `json:"captcha_type"` 23 TCaptchaCaptchaAppId string `json:"tcaptcha_captcha_app_id"` 24 RegisterEnabled bool `json:"registerEnabled"` 25 AppPromotion bool `json:"app_promotion"` 26 WopiExts []string `json:"wopi_exts"` 27 } 28 29 type task struct { 30 Status int `json:"status"` 31 Type int `json:"type"` 32 CreateDate time.Time `json:"create_date"` 33 Progress int `json:"progress"` 34 Error string `json:"error"` 35 } 36 37 // BuildTaskList 构建任务列表响应 38 func BuildTaskList(tasks []model.Task, total int) Response { 39 res := make([]task, 0, len(tasks)) 40 for _, t := range tasks { 41 res = append(res, task{ 42 Status: t.Status, 43 Type: t.Type, 44 CreateDate: t.CreatedAt, 45 Progress: t.Progress, 46 Error: t.Error, 47 }) 48 } 49 50 return Response{Data: map[string]interface{}{ 51 "total": total, 52 "tasks": res, 53 }} 54 } 55 56 func checkSettingValue(setting map[string]string, key string) string { 57 if v, ok := setting[key]; ok { 58 return v 59 } 60 return "" 61 } 62 63 // BuildSiteConfig 站点全局设置 64 func BuildSiteConfig(settings map[string]string, user *model.User, wopiExts []string) Response { 65 var userRes User 66 if user != nil { 67 userRes = BuildUser(*user) 68 } else { 69 userRes = BuildUser(*model.NewAnonymousUser()) 70 } 71 res := Response{ 72 Data: SiteConfig{ 73 SiteName: checkSettingValue(settings, "siteName"), 74 LoginCaptcha: model.IsTrueVal(checkSettingValue(settings, "login_captcha")), 75 RegCaptcha: model.IsTrueVal(checkSettingValue(settings, "reg_captcha")), 76 ForgetCaptcha: model.IsTrueVal(checkSettingValue(settings, "forget_captcha")), 77 EmailActive: model.IsTrueVal(checkSettingValue(settings, "email_active")), 78 Themes: checkSettingValue(settings, "themes"), 79 DefaultTheme: checkSettingValue(settings, "defaultTheme"), 80 HomepageViewMethod: checkSettingValue(settings, "home_view_method"), 81 ShareViewMethod: checkSettingValue(settings, "share_view_method"), 82 Authn: model.IsTrueVal(checkSettingValue(settings, "authn_enabled")), 83 User: userRes, 84 ReCaptchaKey: checkSettingValue(settings, "captcha_ReCaptchaKey"), 85 CaptchaType: checkSettingValue(settings, "captcha_type"), 86 TCaptchaCaptchaAppId: checkSettingValue(settings, "captcha_TCaptcha_CaptchaAppId"), 87 RegisterEnabled: model.IsTrueVal(checkSettingValue(settings, "register_enabled")), 88 AppPromotion: model.IsTrueVal(checkSettingValue(settings, "show_app_promotion")), 89 WopiExts: wopiExts, 90 }} 91 return res 92 }