MCPcopy Create free account
hub / github.com/aiprodcoder/MIXAPI / UpdateUserSetting

Function UpdateUserSetting

controller/user.go:855–956  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

853}
854
855func UpdateUserSetting(c *gin.Context) {
856 var req UpdateUserSettingRequest
857 if err := c.ShouldBindJSON(&req); err != nil {
858 c.JSON(http.StatusOK, gin.H{
859 "success": false,
860 "message": "无效的参数",
861 })
862 return
863 }
864
865 // 验证预警类型
866 if req.QuotaWarningType != dto.NotifyTypeEmail && req.QuotaWarningType != dto.NotifyTypeWebhook {
867 c.JSON(http.StatusOK, gin.H{
868 "success": false,
869 "message": "无效的预警类型",
870 })
871 return
872 }
873
874 // 验证预警阈值
875 if req.QuotaWarningThreshold <= 0 {
876 c.JSON(http.StatusOK, gin.H{
877 "success": false,
878 "message": "预警阈值必须大于0",
879 })
880 return
881 }
882
883 // 如果是webhook类型,验证webhook地址
884 if req.QuotaWarningType == dto.NotifyTypeWebhook {
885 if req.WebhookUrl == "" {
886 c.JSON(http.StatusOK, gin.H{
887 "success": false,
888 "message": "Webhook地址不能为空",
889 })
890 return
891 }
892 // 验证URL格式
893 if _, err := url.ParseRequestURI(req.WebhookUrl); err != nil {
894 c.JSON(http.StatusOK, gin.H{
895 "success": false,
896 "message": "无效的Webhook地址",
897 })
898 return
899 }
900 }
901
902 // 如果是邮件类型,验证邮箱地址
903 if req.QuotaWarningType == dto.NotifyTypeEmail && req.NotificationEmail != "" {
904 // 验证邮箱格式
905 if !strings.Contains(req.NotificationEmail, "@") {
906 c.JSON(http.StatusOK, gin.H{
907 "success": false,
908 "message": "无效的邮箱地址",
909 })
910 return
911 }
912 }

Callers

nothing calls this directly

Calls 6

GetUserByIdFunction · 0.92
ApiErrorFunction · 0.92
ContainsMethod · 0.80
ErrorMethod · 0.80
SetSettingMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected