AddMultipleKeys handles the business logic of creating new keys from a text block. deprecated: use KeyImportService for large imports
(groupID uint, keysText string)
| 61 | // AddMultipleKeys handles the business logic of creating new keys from a text block. |
| 62 | // deprecated: use KeyImportService for large imports |
| 63 | func (s *KeyService) AddMultipleKeys(groupID uint, keysText string) (*AddKeysResult, error) { |
| 64 | keys := s.ParseKeysFromText(keysText) |
| 65 | if len(keys) > maxRequestKeys { |
| 66 | return nil, fmt.Errorf("batch size exceeds the limit of %d keys, got %d", maxRequestKeys, len(keys)) |
| 67 | } |
| 68 | if len(keys) == 0 { |
| 69 | return nil, fmt.Errorf("no valid keys found in the input text") |
| 70 | } |
| 71 | |
| 72 | addedCount, ignoredCount, err := s.processAndCreateKeys(groupID, keys, nil) |
| 73 | if err != nil { |
| 74 | return nil, err |
| 75 | } |
| 76 | |
| 77 | var totalInGroup int64 |
| 78 | if err := s.DB.Model(&models.APIKey{}).Where("group_id = ?", groupID).Count(&totalInGroup).Error; err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | |
| 82 | return &AddKeysResult{ |
| 83 | AddedCount: addedCount, |
| 84 | IgnoredCount: ignoredCount, |
| 85 | TotalInGroup: totalInGroup, |
| 86 | }, nil |
| 87 | } |
| 88 | |
| 89 | // processAndCreateKeys is the lowest-level reusable function for adding keys. |
| 90 | func (s *KeyService) processAndCreateKeys( |
nothing calls this directly
no test coverage detected