Revert "feat: 批量设置用户最大连接数"

This reverts commit 28568244bb.
This commit is contained in:
sagitchu
2026-04-25 22:45:23 +08:00
parent 28568244bb
commit 325baa8adc
6 changed files with 1 additions and 175 deletions
@@ -138,7 +138,6 @@ func (h *Handler) Register(mux *http.ServeMux) {
mux.HandleFunc("/api/v1/user/update", h.userUpdate)
mux.HandleFunc("/api/v1/user/delete", h.userDelete)
mux.HandleFunc("/api/v1/user/reset", h.userResetFlow)
mux.HandleFunc("/api/v1/user/batch-set-max-conn", h.userBatchSetMaxConn)
mux.HandleFunc("/api/v1/user/quota/reset", h.userQuotaReset)
mux.HandleFunc("/api/v1/user/groups", h.userGroups)
mux.HandleFunc("/api/v1/config/get", h.getConfigByName)
@@ -214,26 +214,6 @@ func (h *Handler) userUpdate(w http.ResponseWriter, r *http.Request) {
response.WriteJSON(w, response.OKEmpty())
}
func (h *Handler) userBatchSetMaxConn(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
response.WriteJSON(w, response.ErrDefault("请求失败"))
return
}
var req struct {
UserIDs []int64 `json:"userIds"`
MaxConn int `json:"maxConn"`
}
if err := decodeJSON(r.Body, &req); err != nil || len(req.UserIDs) == 0 {
response.WriteJSON(w, response.ErrDefault("请求参数错误"))
return
}
s, f := h.repo.BatchUpdateUserMaxConn(req.UserIDs, req.MaxConn)
response.WriteJSON(w, response.OK(map[string]interface{}{
"success": s,
"failed": f,
}))
}
func (h *Handler) userGroups(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
response.WriteJSON(w, response.ErrDefault("请求失败"))
+1 -1
View File
@@ -137,7 +137,7 @@ func requiresAdmin(path string) bool {
}
switch path {
case "/api/v1/user/create", "/api/v1/user/list", "/api/v1/user/update", "/api/v1/user/delete", "/api/v1/user/reset", "/api/v1/user/batch-set-max-conn":
case "/api/v1/user/create", "/api/v1/user/list", "/api/v1/user/update", "/api/v1/user/delete", "/api/v1/user/reset":
return true
case "/api/v1/config/update", "/api/v1/config/update-single":
return true
@@ -1320,23 +1320,6 @@ func (r *Repository) BatchUpdateForwardStatus(ids []int64, status int) (int, int
return s, f
}
func (r *Repository) BatchUpdateUserMaxConn(ids []int64, maxConn int) (int, int) {
if r == nil || r.db == nil {
return 0, len(ids)
}
s := 0
f := 0
now := time.Now().UnixMilli()
for _, id := range ids {
if err := r.db.Model(&model.User{}).Where("id = ?", id).Updates(map[string]interface{}{"max_conn": maxConn, "updated_time": now}).Error; err != nil {
f++
} else {
s++
}
}
return s, f
}
func (r *Repository) CreateTunnelTx(tx *gorm.DB, name string, trafficRatio float64, typeVal int, flow int64, now int64, status int, inIP interface{}, inx int, ipPreference string) (int64, error) {
inIPVal := nullStringFromInterface(inIP)
tunnel := model.Tunnel{