MCPcopy Create free account
hub / github.com/tbphp/gpt-load / AddMultipleKeys

Method AddMultipleKeys

internal/services/key_service.go:63–87  ·  view source on GitHub ↗

AddMultipleKeys handles the business logic of creating new keys from a text block. deprecated: use KeyImportService for large imports

(groupID uint, keysText string)

Source from the content-addressed store, hash-verified

61// AddMultipleKeys handles the business logic of creating new keys from a text block.
62// deprecated: use KeyImportService for large imports
63func (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.
90func (s *KeyService) processAndCreateKeys(

Callers

nothing calls this directly

Calls 2

ParseKeysFromTextMethod · 0.95
processAndCreateKeysMethod · 0.95

Tested by

no test coverage detected