阶段更新

This commit is contained in:
2026-07-14 10:09:24 +08:00
parent 3da6718729
commit cc9f6c4d71
13 changed files with 1262 additions and 446 deletions
+144 -9
View File
@@ -401,41 +401,168 @@ func batchAddPoolRows(c *beego.Controller, module string) {
return
}
}
var accounts []string
var tokens []string
seenAccs := make(map[string]bool)
seenTks := make(map[string]bool)
for _, row := range payload.Rows {
acc := strings.TrimSpace(row.Account)
tk := strings.TrimSpace(row.Token)
if acc != "" && !seenAccs[acc] {
seenAccs[acc] = true
accounts = append(accounts, acc)
}
if tk != "" && !seenTks[tk] {
seenTks[tk] = true
tokens = append(tokens, tk)
}
}
existingAccs := make(map[string]bool)
existingTks := make(map[string]bool)
if len(accounts) > 0 || len(tokens) > 0 {
condObj := orm.NewCondition()
subCond := orm.NewCondition()
if len(accounts) > 0 {
subCond = subCond.Or("account__in", accounts)
}
if len(tokens) > 0 {
subCond = subCond.Or("token__in", tokens)
}
switch module {
case "cursor":
var dbRows []models.PlatformAccountPoolCursor
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
case "windsurf":
var dbRows []models.PlatformAccountPoolWindsurf
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
case "krio":
var dbRows []models.PlatformAccountPoolKiro
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
case "codex":
var dbRows []models.PlatformAccountPoolCodex
cond := models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("delete_time__isnull", true)
cond = cond.SetCond(condObj.AndCond(subCond))
if _, err := cond.All(&dbRows, "account", "token"); err == nil {
for _, r := range dbRows {
if r.Account != "" {
existingAccs[r.Account] = true
}
if r.Token != "" {
existingTks[r.Token] = true
}
}
}
}
}
insertedAccs := make(map[string]bool)
insertedTks := make(map[string]bool)
var successCount int
var duplicateCount int
for _, row := range payload.Rows {
acc := strings.TrimSpace(row.Account)
tk := strings.TrimSpace(row.Token)
isDuplicate := false
if row.DataType == "account" {
if existingAccs[acc] || insertedAccs[acc] {
isDuplicate = true
}
} else if row.DataType == "tk" {
if existingTks[tk] || insertedTks[tk] {
isDuplicate = true
}
} else if row.DataType == "account_tk" {
if (acc != "" && (existingAccs[acc] || insertedAccs[acc])) || (tk != "" && (existingTks[tk] || insertedTks[tk])) {
isDuplicate = true
}
}
if isDuplicate {
duplicateCount++
continue
}
if acc != "" {
insertedAccs[acc] = true
}
if tk != "" {
insertedTks[tk] = true
}
switch module {
case "cursor":
_, err = models.Orm.Insert(&models.PlatformAccountPoolCursor{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
case "windsurf":
_, err = models.Orm.Insert(&models.PlatformAccountPoolWindsurf{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
case "krio":
_, err = models.Orm.Insert(&models.PlatformAccountPoolKiro{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
case "codex":
_, err = models.Orm.Insert(&models.PlatformAccountPoolCodex{
DataType: strings.TrimSpace(row.DataType),
Account: strings.TrimSpace(row.Account),
Account: acc,
Password: strings.TrimSpace(row.Password),
Token: strings.TrimSpace(row.Token),
Token: tk,
Remark: strings.TrimSpace(row.Remark),
IsExtracted: 0,
})
@@ -447,8 +574,16 @@ func batchAddPoolRows(c *beego.Controller, module string) {
poolJSONErr(c, 500, 500, "批量添加失败: "+err.Error())
return
}
successCount++
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "批量添加成功",
"data": map[string]interface{}{
"success_count": successCount,
"duplicate_count": duplicateCount,
},
}
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "批量添加成功"}
_ = c.ServeJSON()
}