TestMultipleKeys handles a one-off validation test for multiple keys.
(c *gin.Context)
| 327 | |
| 328 | // TestMultipleKeys handles a one-off validation test for multiple keys. |
| 329 | func (s *Server) TestMultipleKeys(c *gin.Context) { |
| 330 | var req KeyTextRequest |
| 331 | if err := c.ShouldBindJSON(&req); err != nil { |
| 332 | response.Error(c, app_errors.NewAPIError(app_errors.ErrInvalidJSON, err.Error())) |
| 333 | return |
| 334 | } |
| 335 | |
| 336 | groupDB, ok := s.findGroupByID(c, req.GroupID) |
| 337 | if !ok { |
| 338 | return |
| 339 | } |
| 340 | |
| 341 | group, err := s.GroupManager.GetGroupByName(groupDB.Name) |
| 342 | if err != nil { |
| 343 | response.ErrorI18nFromAPIError(c, app_errors.ErrResourceNotFound, "validation.group_not_found") |
| 344 | return |
| 345 | } |
| 346 | |
| 347 | if !validateKeysText(c, req.KeysText) { |
| 348 | return |
| 349 | } |
| 350 | |
| 351 | start := time.Now() |
| 352 | results, err := s.KeyService.TestMultipleKeys(group, req.KeysText) |
| 353 | duration := time.Since(start).Milliseconds() |
| 354 | if err != nil { |
| 355 | if strings.Contains(err.Error(), "batch size exceeds the limit") { |
| 356 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error())) |
| 357 | } else if err.Error() == "no valid keys found in the input text" { |
| 358 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error())) |
| 359 | } else { |
| 360 | response.Error(c, app_errors.ParseDBError(err)) |
| 361 | } |
| 362 | return |
| 363 | } |
| 364 | |
| 365 | response.Success(c, gin.H{ |
| 366 | "results": results, |
| 367 | "total_duration": duration, |
| 368 | }) |
| 369 | } |
| 370 | |
| 371 | // ValidateGroupKeys initiates a manual validation task for all keys in a group. |
| 372 | func (s *Server) ValidateGroupKeys(c *gin.Context) { |
nothing calls this directly
no test coverage detected