RestoreMultipleKeys handles restoring keys from a text block within a specific group.
(c *gin.Context)
| 296 | |
| 297 | // RestoreMultipleKeys handles restoring keys from a text block within a specific group. |
| 298 | func (s *Server) RestoreMultipleKeys(c *gin.Context) { |
| 299 | var req KeyTextRequest |
| 300 | if err := c.ShouldBindJSON(&req); err != nil { |
| 301 | response.Error(c, app_errors.NewAPIError(app_errors.ErrInvalidJSON, err.Error())) |
| 302 | return |
| 303 | } |
| 304 | |
| 305 | if _, ok := s.findGroupByID(c, req.GroupID); !ok { |
| 306 | return |
| 307 | } |
| 308 | |
| 309 | if !validateKeysText(c, req.KeysText) { |
| 310 | return |
| 311 | } |
| 312 | |
| 313 | result, err := s.KeyService.RestoreMultipleKeys(req.GroupID, req.KeysText) |
| 314 | if err != nil { |
| 315 | if strings.Contains(err.Error(), "batch size exceeds the limit") { |
| 316 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error())) |
| 317 | } else if err.Error() == "no valid keys found in the input text" { |
| 318 | response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error())) |
| 319 | } else { |
| 320 | response.Error(c, app_errors.ParseDBError(err)) |
| 321 | } |
| 322 | return |
| 323 | } |
| 324 | |
| 325 | response.Success(c, result) |
| 326 | } |
| 327 | |
| 328 | // TestMultipleKeys handles a one-off validation test for multiple keys. |
| 329 | func (s *Server) TestMultipleKeys(c *gin.Context) { |
nothing calls this directly
no test coverage detected