(ctx context.Context, eid, userID int64, role int64, keyType string, libraryID *int64)
| 74 | } |
| 75 | |
| 76 | func (s *APIKeyService) ListAPIKeys(ctx context.Context, eid, userID int64, role int64, keyType string, libraryID *int64) ([]model.APIKey, error) { |
| 77 | if libraryID != nil { |
| 78 | if _, err := s.resolveAPIKeyScope(eid, userID, role, libraryID); err != nil { |
| 79 | return nil, err |
| 80 | } |
| 81 | return model.GetAPIKeysByEidAndLibraryID(eid, *libraryID) |
| 82 | } |
| 83 | |
| 84 | if role < model.RoleAdminUser { |
| 85 | return []model.APIKey{}, nil |
| 86 | } |
| 87 | |
| 88 | switch keyType { |
| 89 | case "", "library": |
| 90 | return model.GetAPIKeysByEidWithLibrary(eid) |
| 91 | case "personal": |
| 92 | return model.GetAPIKeysByEidAndCreatorIDWithoutLibrary(eid, userID) |
| 93 | default: |
| 94 | return nil, errors.New("无效的API密钥类型参数") |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | func (s *APIKeyService) DeleteAPIKey(ctx context.Context, eid, userID int64, role int64, keyID int64, libraryID *int64) error { |
| 99 | apiKey, err := model.GetAPIKeyByID(keyID) |
no test coverage detected