This commit is contained in:
2026-06-24 10:04:03 +08:00
parent b103192fac
commit 0f961789dc
538 changed files with 128210 additions and 128008 deletions
+66 -66
View File
@@ -1,66 +1,66 @@
package controllers
import (
"strings"
"time"
"server/models"
"server/pkg/tokenprobe"
)
func poolTableName(module string) string {
switch module {
case "cursor":
return new(models.PlatformAccountPoolCursor).TableName()
case "windsurf":
return new(models.PlatformAccountPoolWindsurf).TableName()
case "krio":
return new(models.PlatformAccountPoolKiro).TableName()
case "codex":
return new(models.PlatformAccountPoolCodex).TableName()
default:
return ""
}
}
// poolNeedsTokenProbe account 类型无 Token,无需探测;tk / account_tk 需探测。
func poolNeedsTokenProbe(dataType, token string) bool {
if strings.TrimSpace(token) == "" {
return false
}
return dataType != "account"
}
func poolSaveCursorIsUsed(id uint64, isUsed int8) {
_, _ = models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("id", id).
Update(map[string]interface{}{
"is_used": isUsed,
"update_time": time.Now(),
})
}
// poolProbeToken 探测 Tokencursor 模块会回写 is_used。
func poolProbeToken(module, dataType, token string, rowID uint64) bool {
if !poolNeedsTokenProbe(dataType, token) {
return true
}
r := tokenprobe.ProbeOfficial(module, token)
if module == "cursor" && rowID > 0 {
var isUsed int8
if r.OK {
isUsed = 1
}
poolSaveCursorIsUsed(rowID, isUsed)
}
return r.OK
}
// poolIsUsedAvailable 已有探测结论时:1=可用,0=不可用,nil=未探测。
func poolIsUsedAvailable(isUsed *int8) (known bool, available bool) {
if isUsed == nil {
return false, false
}
return true, *isUsed == 1
}
package controllers
import (
"strings"
"time"
"server/models"
"server/pkg/tokenprobe"
)
func poolTableName(module string) string {
switch module {
case "cursor":
return new(models.PlatformAccountPoolCursor).TableName()
case "windsurf":
return new(models.PlatformAccountPoolWindsurf).TableName()
case "krio":
return new(models.PlatformAccountPoolKiro).TableName()
case "codex":
return new(models.PlatformAccountPoolCodex).TableName()
default:
return ""
}
}
// poolNeedsTokenProbe account 类型无 Token,无需探测;tk / account_tk 需探测。
func poolNeedsTokenProbe(dataType, token string) bool {
if strings.TrimSpace(token) == "" {
return false
}
return dataType != "account"
}
func poolSaveCursorIsUsed(id uint64, isUsed int8) {
_, _ = models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("id", id).
Update(map[string]interface{}{
"is_used": isUsed,
"update_time": time.Now(),
})
}
// poolProbeToken 探测 Tokencursor 模块会回写 is_used。
func poolProbeToken(module, dataType, token string, rowID uint64) bool {
if !poolNeedsTokenProbe(dataType, token) {
return true
}
r := tokenprobe.ProbeOfficial(module, token)
if module == "cursor" && rowID > 0 {
var isUsed int8
if r.OK {
isUsed = 1
}
poolSaveCursorIsUsed(rowID, isUsed)
}
return r.OK
}
// poolIsUsedAvailable 已有探测结论时:1=可用,0=不可用,nil=未探测。
func poolIsUsedAvailable(isUsed *int8) (known bool, available bool) {
if isUsed == nil {
return false, false
}
return true, *isUsed == 1
}