mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-29 04:08:12 +08:00
Go: add context, part6 (#17399)
Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -258,8 +258,9 @@ func (h *Handler) CreateUser(c *gin.Context) {
|
||||
if req.Role == "" {
|
||||
req.Role = "user"
|
||||
}
|
||||
ctx := c.Request.Context()
|
||||
|
||||
userInfo, err := h.service.CreateUser(req.Username, req.Password, req.Role)
|
||||
userInfo, err := h.service.CreateUser(ctx, req.Username, req.Password, req.Role)
|
||||
if err != nil {
|
||||
common.ErrorWithCode(c, common.CodeServerError, err.Error())
|
||||
return
|
||||
|
||||
@@ -170,7 +170,7 @@ func (s *Service) ListUsers(pageIndex, pageSize int, name, status, sort, orderBy
|
||||
// Returns:
|
||||
// - map[string]interface{}: user information without password
|
||||
// - error: error message
|
||||
func (s *Service) CreateUser(username, password, role string) (map[string]interface{}, error) {
|
||||
func (s *Service) CreateUser(ctx context.Context, username, password, role string) (map[string]interface{}, error) {
|
||||
emailRegex := regexp.MustCompile(`^[\w\._-]+@([\w_-]+\.)+[\w-]{2,}$`)
|
||||
if !emailRegex.MatchString(username) {
|
||||
return nil, fmt.Errorf("invalid email address: %s", username)
|
||||
@@ -285,7 +285,7 @@ func (s *Service) CreateUser(username, password, role string) (map[string]interf
|
||||
}
|
||||
|
||||
// 4. Create tenant LLM configurations
|
||||
tenantLLMs, err := s.getInitTenantLLM(userID)
|
||||
tenantLLMs, err := s.getInitTenantLLM(ctx, userID)
|
||||
if err != nil {
|
||||
common.Warn("failed to get init tenant LLM configs", zap.Error(err))
|
||||
// Continue without LLM configs - not a critical error
|
||||
@@ -333,7 +333,7 @@ func (s *Service) CreateUser(username, password, role string) (map[string]interf
|
||||
|
||||
// getInitTenantLLM gets initial tenant LLM configurations
|
||||
// This matches Python's get_init_tenant_llm function
|
||||
func (s *Service) getInitTenantLLM(userID string) ([]*entity.TenantLLM, error) {
|
||||
func (s *Service) getInitTenantLLM(ctx context.Context, userID string) ([]*entity.TenantLLM, error) {
|
||||
cfg := server.GetConfig()
|
||||
if cfg == nil {
|
||||
return nil, fmt.Errorf("config not initialized")
|
||||
@@ -366,7 +366,7 @@ func (s *Service) getInitTenantLLM(userID string) ([]*entity.TenantLLM, error) {
|
||||
|
||||
// Get LLMs for each unique factory
|
||||
for _, factoryConfig := range uniqueFactories {
|
||||
models, err := s.llmDAO.GetByFactory(factoryConfig.Factory)
|
||||
models, err := s.llmDAO.GetByFactory(ctx, dao.DB, factoryConfig.Factory)
|
||||
if err != nil {
|
||||
common.Warn("failed to get LLMs for factory", zap.String("factory", factoryConfig.Factory), zap.Error(err))
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user