AddMultipleKeys handles creating new keys from a text block within a specific group.
(c *gin.Context)
| 80 | |
| 81 | // AddMultipleKeys handles creating new keys from a text block within a specific group. |
| 82 | func (s *Server) AddMultipleKeys(c *gin.Context) { |
| 83 | var req KeyTextRequest |
| 84 | if err := c.ShouldBindJSON(&req); err != nil { |
| 85 | response.Error(c, app_errors.NewAPIError(app_errors.ErrInvalidJSON, err.Error())) |
| 86 | return |
| 87 | } |
| 88 | |
| 89 | if _, ok := s.findGroupByID(c, req.GroupID); !ok { |
| 90 | return |
| 91 | } |
| 92 | |
| 93 | if !validateKeysText(c, req.KeysText) { |
| 94 | return |
| 95 | } |
| 96 | |
| 97 | result, err := s.KeyService.AddMultipleKeys(req.GroupID, req.KeysText) |
| 98 | if err != nil { |
| 99 | if strings.Contains(err.Error(), "batch size exceeds the limit") { |
| 100 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error())) |
| 101 | } else if err.Error() == "no valid keys found in the input text" { |
| 102 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error())) |
| 103 | } else { |
| 104 | response.Error(c, app_errors.ParseDBError(err)) |
| 105 | } |
| 106 | return |
| 107 | } |
| 108 | |
| 109 | response.Success(c, result) |
| 110 | } |
| 111 | |
| 112 | // AddMultipleKeysAsync handles creating new keys from a text block or file within a specific group. |
| 113 | func (s *Server) AddMultipleKeysAsync(c *gin.Context) { |
nothing calls this directly
no test coverage detected