更新检测流程

This commit is contained in:
2026-06-05 13:18:57 +08:00
parent 81f5039458
commit 761a5cb69c
15 changed files with 2446 additions and 311 deletions
+68 -64
View File
@@ -91,7 +91,7 @@ func (c *ApiGetCardController) GetCard() {
}
func (c *ApiGetCardController) extractCursor(platform, dataType string, now time.Time) {
for {
c.extractWithProbe("cursor", platform, dataType, now, func() (uint64, *string, *string, string, string, *int8, error) {
var row models.PlatformAccountPoolCursor
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("is_extracted", 0).
@@ -100,6 +100,55 @@ func (c *ApiGetCardController) extractCursor(platform, dataType string, now time
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
return 0, nil, nil, "", "", nil, err
}
return row.ID, &row.Account, &row.Password, row.Token, row.DataType, row.IsUsed, nil
})
}
func (c *ApiGetCardController) extractWindsurf(platform, dataType string, now time.Time) {
c.extractWithProbe("windsurf", platform, dataType, now, func() (uint64, *string, *string, string, string, *int8, error) {
var row models.PlatformAccountPoolWindsurf
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).
Filter("is_extracted", 0).
Filter("delete_time__isnull", true)
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
return 0, nil, nil, "", "", nil, err
}
return row.ID, &row.Account, &row.Password, row.Token, row.DataType, nil, nil
})
}
func (c *ApiGetCardController) extractKrio(platform, dataType string, now time.Time) {
c.extractWithProbe("krio", platform, dataType, now, func() (uint64, *string, *string, string, string, *int8, error) {
var row models.PlatformAccountPoolKiro
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).
Filter("is_extracted", 0).
Filter("delete_time__isnull", true)
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
return 0, nil, nil, "", "", nil, err
}
return row.ID, &row.Account, &row.Password, row.Token, row.DataType, nil, nil
})
}
type poolRowFetcher func() (id uint64, account, password *string, token, rowDataType string, isUsed *int8, err error)
// extractWithProbe 按 id 顺序提取并探测 Token 可用性;不可用则标记已提取并继续下一条。
func (c *ApiGetCardController) extractWithProbe(
module, platform, dataType string,
now time.Time,
fetch poolRowFetcher,
) {
for {
id, account, password, token, rowDataType, isUsed, err := fetch()
if err != nil {
if err == orm.ErrNoRows {
c.cardErr(404, 404, "暂无可用卡密")
} else {
@@ -108,85 +157,40 @@ func (c *ApiGetCardController) extractCursor(platform, dataType string, now time
return
}
_, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("id", row.ID).
tableName := poolTableName(module)
if tableName == "" {
c.cardErr(500, 500, "无效模块")
return
}
_, err = models.Orm.QueryTable(tableName).
Filter("id", id).
Update(map[string]interface{}{
"is_extracted": 1,
"extracted_time": now,
"extracted_platform": platform,
"update_time": now,
})
if err != nil {
c.cardErr(500, 500, "提取失败")
return
}
// Cursor 号池需要先判断可用状态:is_used=1 才发送给前端;
// is_used=0(已用完/不可用)或 NULL(未探测)则继续提取下一条。
if row.IsUsed != nil && *row.IsUsed == 1 {
c.cardOK(buildCardResult(&row.Account, &row.Password, row.Token, row.DataType))
return
// 已有探测结论:可用则直接返回,不可用则继续下一条。
if known, available := poolIsUsedAvailable(isUsed); known {
if available {
c.cardOK(buildCardResult(account, password, token, rowDataType))
return
}
continue
}
}
}
func (c *ApiGetCardController) extractWindsurf(platform, dataType string, now time.Time) {
var row models.PlatformAccountPoolWindsurf
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).
Filter("is_extracted", 0).
Filter("delete_time__isnull", true)
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
if err == orm.ErrNoRows {
c.cardErr(404, 404, "暂无可用卡密")
} else {
c.cardErr(500, 500, "查询失败")
if !poolProbeToken(module, rowDataType, token, id) {
continue
}
return
}
_, err := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).
Filter("id", row.ID).
Update(map[string]interface{}{
"is_extracted": 1,
"extracted_time": now,
"extracted_platform": platform,
})
if err != nil {
c.cardErr(500, 500, "提取失败")
return
}
c.cardOK(buildCardResult(&row.Account, &row.Password, row.Token, row.DataType))
}
func (c *ApiGetCardController) extractKrio(platform, dataType string, now time.Time) {
var row models.PlatformAccountPoolKiro
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).
Filter("is_extracted", 0).
Filter("delete_time__isnull", true)
if dataType != "" {
qs = qs.Filter("data_type", dataType)
}
if err := qs.OrderBy("id").One(&row); err != nil {
if err == orm.ErrNoRows {
c.cardErr(404, 404, "暂无可用卡密")
} else {
c.cardErr(500, 500, "查询失败")
}
c.cardOK(buildCardResult(account, password, token, rowDataType))
return
}
_, err := models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).
Filter("id", row.ID).
Update(map[string]interface{}{
"is_extracted": 1,
"extracted_time": now,
"extracted_platform": platform,
})
if err != nil {
c.cardErr(500, 500, "提取失败")
return
}
c.cardOK(buildCardResult(&row.Account, &row.Password, row.Token, row.DataType))
}
// buildCardResult 根据账号类型返回格式化字符串