feat: add folder uploads and archives with simpler account and plan forms

This commit is contained in:
canglan committed 2026-11-15 18:57:02 +08:00
1 parent 9afd7d0067
commit faaa614cee
41 files changed
+1027 -71

No files matched your search

+24 -3
View File
@@ -27,6 +27,7 @@ import (
type batchRow struct {
Name string `json:"name,omitempty"`
Slug string `json:"slug,omitempty"`
LoginName string `json:"loginName,omitempty"`
Email string `json:"email,omitempty"`
DisplayName string `json:"displayName,omitempty"`
Password string `json:"password,omitempty"`
@@ -128,6 +129,16 @@ func (s *Server) normalizeBatch(ctx context.Context, input *batchRequest) ([]bat
var validation error
switch input.Operation {
case "create_users":
row.LoginName = strings.ToLower(strings.TrimSpace(row.LoginName))
if row.LoginName != "" {
if !tenantSlugPattern.MatchString(row.LoginName) {
validation = errors.New("登录账号格式无效")
}
row.Slug = accountSlug(row.LoginName)
if row.Name == "" {
row.Name = row.DisplayName
}
}
row.Slug = strings.ToLower(strings.TrimSpace(row.Slug))
row.Email = strings.ToLower(strings.TrimSpace(row.Email))
row.Name = strings.TrimSpace(row.Name)
@@ -150,17 +161,24 @@ func (s *Server) normalizeBatch(ctx context.Context, input *batchRequest) ([]bat
}
key := "user:" + row.Email
slugKey := "slug:" + row.Slug
if validation == nil && (seen[key] || seen[slugKey]) {
if validation == nil && (seen[key] || seen[slugKey] || (row.LoginName != "" && seen["login:"+row.LoginName])) {
validation = errors.New("同批邮箱或用户标识重复")
}
seen[key] = true
seen[slugKey] = true
if row.LoginName != "" {
seen["login:"+row.LoginName] = true
}
if validation == nil {
exists, e := s.store.AccountIdentityExists(ctx, row.Slug, row.Email)
if e != nil {
validation = errors.New("无法核对现有账号")
} else if exists {
validation = errors.New("邮箱或用户标识已存在")
} else if row.LoginName != "" {
if exists, e = s.store.AccountIdentityExists(ctx, row.Slug, row.LoginName); e != nil || exists {
validation = errors.New("登录账号已存在或无法核对")
}
}
}
preview.Label = row.Email
@@ -610,9 +628,12 @@ func (s *Server) performBatchRow(ctx context.Context, operation string, row batc
return result, err
}
}
id, err := s.store.CreateTenant(ctx, store.NewTenant{Slug: row.Slug, Name: row.Name, Email: row.Email, DisplayName: row.DisplayName, Password: row.Password, PlanID: row.PlanID})
id, err := s.store.CreateTenant(ctx, store.NewTenant{LoginName: row.LoginName, Slug: row.Slug, Name: row.Name, Email: row.Email, DisplayName: row.DisplayName, Password: row.Password, PlanID: row.PlanID})
result.ResourceID = id
result.Login = row.Email
result.Login = row.LoginName
if result.Login == "" {
result.Login = row.Email
}
result.Password = row.Password
return result, err
}