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

Function AddToken

controller/token.go:108–160  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

106}
107
108func AddToken(c *gin.Context) {
109 token := model.Token{}
110 err := c.ShouldBindJSON(&token)
111 if err != nil {
112 common.ApiError(c, err)
113 return
114 }
115 if len(token.Name) > 30 {
116 c.JSON(http.StatusOK, gin.H{
117 "success": false,
118 "message": "令牌名称过长",
119 })
120 return
121 }
122 key, err := common.GenerateKey()
123 if err != nil {
124 c.JSON(http.StatusOK, gin.H{
125 "success": false,
126 "message": "生成令牌失败",
127 })
128 common.SysError("failed to generate token key: " + err.Error())
129 return
130 }
131 cleanToken := model.Token{
132 UserId: c.GetInt("id"),
133 Name: token.Name,
134 Key: key,
135 CreatedTime: common.GetTimestamp(),
136 AccessedTime: common.GetTimestamp(),
137 ExpiredTime: token.ExpiredTime,
138 RemainQuota: token.RemainQuota,
139 UnlimitedQuota: token.UnlimitedQuota,
140 ModelLimitsEnabled: token.ModelLimitsEnabled,
141 ModelLimits: token.ModelLimits,
142 AllowIps: token.AllowIps,
143 Group: token.Group,
144 RateLimitPerMinute: token.RateLimitPerMinute,
145 RateLimitPerDay: token.RateLimitPerDay,
146 LastRateLimitReset: 0,
147 ChannelTag: token.ChannelTag,
148 TotalUsageLimit: token.TotalUsageLimit,
149 }
150 err = cleanToken.Insert()
151 if err != nil {
152 common.ApiError(c, err)
153 return
154 }
155 c.JSON(http.StatusOK, gin.H{
156 "success": true,
157 "message": "",
158 })
159 return
160}
161
162func DeleteToken(c *gin.Context) {
163 id, _ := strconv.Atoi(c.Param("id"))

Callers

nothing calls this directly

Calls 6

InsertMethod · 0.95
ApiErrorFunction · 0.92
GenerateKeyFunction · 0.92
SysErrorFunction · 0.92
GetTimestampFunction · 0.92
ErrorMethod · 0.80

Tested by

no test coverage detected