更新检测流程
This commit is contained in:
@@ -621,24 +621,70 @@ func replenishPoolRow(c *beego.Controller, module string) {
|
||||
|
||||
switch module {
|
||||
case "cursor":
|
||||
var row models.PlatformAccountPoolCursor
|
||||
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
|
||||
Filter("is_extracted", 0).Filter("data_type", payload.Type).
|
||||
OrderBy("id").One(&row); err != nil {
|
||||
poolJSONErr(c, 404, 404, "暂无可用账号")
|
||||
return
|
||||
checkedCount := 0
|
||||
unavailableCount := 0
|
||||
|
||||
for {
|
||||
var row models.PlatformAccountPoolCursor
|
||||
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
|
||||
Filter("is_extracted", 0).Filter("data_type", payload.Type).
|
||||
OrderBy("id").One(&row); err != nil {
|
||||
msg := "暂无可用账号"
|
||||
if checkedCount > 0 {
|
||||
msg = fmt.Sprintf("已检测%d个账号,其中%d个不可用,暂无可用账号", checkedCount, unavailableCount)
|
||||
}
|
||||
poolJSONErr(c, 404, 404, msg)
|
||||
return
|
||||
}
|
||||
|
||||
checkedCount++
|
||||
isAvailable := poolProbeToken("cursor", row.DataType, row.Token, row.ID)
|
||||
if !isAvailable {
|
||||
unavailableCount++
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", row.ID).Update(map[string]interface{}{
|
||||
// 补号流程检测出来不可用/已用完的号,仍然归类为“补号”记录。
|
||||
// 不要写成已提取/已用完状态;只有接口提取后再标记不可用的号才归到已提取侧。
|
||||
"is_extracted": int8(2),
|
||||
"is_used": int8(0),
|
||||
"extracted_time": now,
|
||||
"extracted_platform": platform,
|
||||
"remark": remark,
|
||||
"update_time": now,
|
||||
}); err != nil {
|
||||
poolJSONErr(c, 500, 500, "补号检测失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
if _, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", row.ID).Update(map[string]interface{}{
|
||||
"is_extracted": int8(2),
|
||||
"is_used": int8(1),
|
||||
"extracted_time": now,
|
||||
"extracted_platform": platform,
|
||||
"remark": remark,
|
||||
"update_time": now,
|
||||
}); err != nil {
|
||||
poolJSONErr(c, 500, 500, "补号失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
row.IsExtracted = 2
|
||||
isUsed := int8(1)
|
||||
row.IsUsed = &isUsed
|
||||
row.ExtractedTime = &now
|
||||
row.ExtractedPlatform = &platform
|
||||
row.Remark = remark
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 200,
|
||||
"msg": "补号成功",
|
||||
"data": row,
|
||||
"probe": map[string]interface{}{
|
||||
"checkedCount": checkedCount,
|
||||
"unavailableCount": unavailableCount,
|
||||
},
|
||||
}
|
||||
break
|
||||
}
|
||||
if _, err = models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", row.ID).Update(map[string]interface{}{
|
||||
"is_extracted": int8(2), "extracted_time": now, "extracted_platform": platform, "remark": remark,
|
||||
}); err != nil {
|
||||
poolJSONErr(c, 500, 500, "补号失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
row.IsExtracted = 2
|
||||
row.ExtractedTime = &now
|
||||
row.ExtractedPlatform = &platform
|
||||
row.Remark = remark
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "补号成功", "data": row}
|
||||
case "windsurf":
|
||||
var row models.PlatformAccountPoolWindsurf
|
||||
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).
|
||||
@@ -973,12 +1019,12 @@ func probePoolToken(c *beego.Controller, module string) {
|
||||
if r.StreamNote != "" {
|
||||
data["streamNote"] = r.StreamNote
|
||||
}
|
||||
// Cursor 探测状态只按底层探针结论 r.OK 保存。
|
||||
// 注意:客户端版本过旧只是 warning,Token 仍可用时 r.OK=true,不能因此写成已用完。
|
||||
if module == "cursor" && payload.ID > 0 && r.HTTPStatus == http.StatusOK {
|
||||
var isUsed int8
|
||||
isUsed := int8(0)
|
||||
if r.OK {
|
||||
isUsed = 1
|
||||
} else {
|
||||
isUsed = 0
|
||||
}
|
||||
if _, uerr := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).Filter("id", payload.ID).Update(orm.Params{
|
||||
"is_used": isUsed,
|
||||
@@ -995,6 +1041,62 @@ func probePoolToken(c *beego.Controller, module string) {
|
||||
_ = c.ServeJSON()
|
||||
}
|
||||
|
||||
func poolTableName(module string) string {
|
||||
switch module {
|
||||
case "cursor":
|
||||
return (&models.PlatformAccountPoolCursor{}).TableName()
|
||||
case "windsurf":
|
||||
return (&models.PlatformAccountPoolWindsurf{}).TableName()
|
||||
case "krio":
|
||||
return (&models.PlatformAccountPoolKiro{}).TableName()
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func poolIsUsedAvailable(isUsed *int8) (known bool, available bool) {
|
||||
if isUsed == nil {
|
||||
return false, false
|
||||
}
|
||||
switch *isUsed {
|
||||
case 1:
|
||||
return true, true
|
||||
case 0:
|
||||
return true, false
|
||||
default:
|
||||
return false, false
|
||||
}
|
||||
}
|
||||
|
||||
func poolProbeToken(module, rowDataType, token string, id uint64) bool {
|
||||
token = strings.TrimSpace(token)
|
||||
if rowDataType == "account" || token == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
r := tokenprobe.ProbeOfficial(module, token)
|
||||
|
||||
// Cursor 自动探测只按底层探针结论 r.OK 判定。
|
||||
// 客户端版本过旧是 warning,不代表 Token 已用完;只有 tokenprobe 明确判定额度用尽/不可用时 r.OK 才为 false。
|
||||
available := r.OK
|
||||
|
||||
// 更新数据库中的 is_used 字段
|
||||
if module == "cursor" && id > 0 {
|
||||
isUsed := int8(0)
|
||||
if available {
|
||||
isUsed = 1
|
||||
}
|
||||
_, _ = models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
|
||||
Filter("id", id).
|
||||
Update(orm.Params{
|
||||
"is_used": isUsed,
|
||||
"update_time": time.Now(),
|
||||
})
|
||||
}
|
||||
|
||||
return available
|
||||
}
|
||||
|
||||
func (c *PlatformAccountPoolCursorController) List() { listPoolRows(&c.Controller, "cursor") }
|
||||
func (c *PlatformAccountPoolCursorController) Add() { addPoolRow(&c.Controller, "cursor") }
|
||||
func (c *PlatformAccountPoolCursorController) BatchAdd() { batchAddPoolRows(&c.Controller, "cursor") }
|
||||
|
||||
Reference in New Issue
Block a user