feat: 密钥调整为异步任务,取消数量限制

This commit is contained in:
tbphp
2025-07-20 08:52:54 +08:00
parent 86c28dc20c
commit 90498298bf
12 changed files with 213 additions and 40 deletions

View File

@@ -23,6 +23,7 @@ type Server struct {
KeyManualValidationService *services.KeyManualValidationService
TaskService *services.TaskService
KeyService *services.KeyService
KeyImportService *services.KeyImportService
LogService *services.LogService
CommonHandler *CommonHandler
}
@@ -37,6 +38,7 @@ type NewServerParams struct {
KeyManualValidationService *services.KeyManualValidationService
TaskService *services.TaskService
KeyService *services.KeyService
KeyImportService *services.KeyImportService
LogService *services.LogService
CommonHandler *CommonHandler
}
@@ -51,6 +53,7 @@ func NewServer(params NewServerParams) *Server {
KeyManualValidationService: params.KeyManualValidationService,
TaskService: params.TaskService,
KeyService: params.KeyService,
KeyImportService: params.KeyImportService,
LogService: params.LogService,
CommonHandler: params.CommonHandler,
}

View File

@@ -34,10 +34,6 @@ func validateKeysText(keysText string) error {
return fmt.Errorf("keys text cannot be empty")
}
if len(keysText) > 10*1024*1024 {
return fmt.Errorf("keys text is too large (max 10MB)")
}
return nil
}
@@ -98,6 +94,33 @@ func (s *Server) AddMultipleKeys(c *gin.Context) {
response.Success(c, result)
}
// AddMultipleKeysAsync handles creating new keys from a text block within a specific group.
func (s *Server) AddMultipleKeysAsync(c *gin.Context) {
var req KeyTextRequest
if err := c.ShouldBindJSON(&req); err != nil {
response.Error(c, app_errors.NewAPIError(app_errors.ErrInvalidJSON, err.Error()))
return
}
group, ok := s.findGroupByID(c, req.GroupID)
if !ok {
return
}
if err := validateKeysText(req.KeysText); err != nil {
response.Error(c, app_errors.NewAPIError(app_errors.ErrValidation, err.Error()))
return
}
taskStatus, err := s.KeyImportService.StartImportTask(group, req.KeysText)
if err != nil {
response.Error(c, app_errors.NewAPIError(app_errors.ErrTaskInProgress, err.Error()))
return
}
response.Success(c, taskStatus)
}
// ListKeysInGroup handles listing all keys within a specific group with pagination.
func (s *Server) ListKeysInGroup(c *gin.Context) {
groupID, err := validateGroupIDFromQuery(c)