优化账号检测

This commit is contained in:
扫地僧 2026-06-17 00:18:39 +08:00
parent 080db544ea
commit ffe8a2a2fb
3 changed files with 67 additions and 9 deletions

5
.codegraph/.gitignore vendored Normal file
View File

@ -0,0 +1,5 @@
# CodeGraph data files — local to each machine, not for committing.
# Ignore everything in .codegraph/ except this file itself, so transient
# files (the database, daemon.pid, sockets, logs) never show up in git.
*
!.gitignore

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
"time"
"server/models" "server/models"
@ -14,9 +15,9 @@ import (
// ApiCursorDetectController Cursor Token 顺序读取接口(不改变号池状态) // ApiCursorDetectController Cursor Token 顺序读取接口(不改变号池状态)
// //
// 用途: // 用途:
// - 前端传入 start_id/current_id/id从该 ID 开始按 id 从小到大读取 Cursor Token。 // - 前端传入 start_id/current_id/id直接读取该 ID 对应的 Cursor Token。
// - 只读取未提取记录,不更新 is_extracted、extracted_time、extracted_platform、is_used 等任何状态。 // - 只读取记录,不更新 is_extracted、extracted_time、extracted_platform、is_used 等任何状态。
// - 如果传入 ID 对应记录已提取,会自动跳过,继续找下一条未提取记录 // - 不再跳过已提取的记录,输入什么 ID 就提取什么 ID
// - 返回 next_id前端下一次点击时传 next_id即可实现 11 -> 12 -> 13 递增读取。 // - 返回 next_id前端下一次点击时传 next_id即可实现 11 -> 12 -> 13 递增读取。
// //
// 示例: // 示例:
@ -40,6 +41,54 @@ func (c *ApiCursorDetectController) cursorDetectJSONErr(httpStatus, code int, ms
_ = c.ServeJSON() _ = c.ServeJSON()
} }
func (c *ApiCursorDetectController) setTokenUsableByID(isUsed int8) {
id, err := c.readStartID()
if err != nil {
c.cursorDetectJSONErr(400, 400, err.Error())
return
}
now := time.Now()
updated, err := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("id", id).
Filter("delete_time__isnull", true).
Update(orm.Params{
"is_used": isUsed,
"update_time": now,
})
if err != nil {
c.cursorDetectJSONErr(500, 500, "更新失败: "+err.Error())
return
}
if updated == 0 {
c.cursorDetectJSONErr(404, 404, "当前 ID 数据不存在或已删除")
return
}
c.Data["json"] = map[string]interface{}{
"code": 200,
"msg": "success",
"data": map[string]interface{}{
"id": id,
"is_used": isUsed,
"is_available": isUsed == 1,
"state_changed": true,
"update_time": now,
},
}
_ = c.ServeJSON()
}
// MarkTokenAvailable 将当前 ID 的 Cursor Token 标记为可用。
func (c *ApiCursorDetectController) MarkTokenAvailable() {
c.setTokenUsableByID(1)
}
// MarkTokenUnavailable 将当前 ID 的 Cursor Token 标记为不可用/用完。
func (c *ApiCursorDetectController) MarkTokenUnavailable() {
c.setTokenUsableByID(0)
}
// PeekToken 按 ID 顺序读取 Cursor Token不改变任何状态。 // PeekToken 按 ID 顺序读取 Cursor Token不改变任何状态。
func (c *ApiCursorDetectController) PeekToken() { func (c *ApiCursorDetectController) PeekToken() {
startID, err := c.readStartID() startID, err := c.readStartID()
@ -59,17 +108,15 @@ func (c *ApiCursorDetectController) PeekToken() {
var row models.PlatformAccountPoolCursor var row models.PlatformAccountPoolCursor
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)). qs := models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)).
Filter("id__gte", startID). Filter("id", startID).
Filter("data_type", dataType). Filter("data_type", dataType).
Filter("delete_time__isnull", true). Filter("delete_time__isnull", true).
Filter("extracted_time__isnull", true).
Filter("is_extracted", 0).
Exclude("token", "") Exclude("token", "")
err = qs.OrderBy("id").One(&row) err = qs.One(&row)
if err != nil { if err != nil {
if err == orm.ErrNoRows { if err == orm.ErrNoRows {
c.cursorDetectJSONErr(404, 404, "从当前 ID 开始暂无未提取 Cursor Token") c.cursorDetectJSONErr(404, 404, "指定 ID 的 Cursor Token 不存在或已删除")
return return
} }
c.cursorDetectJSONErr(500, 500, "查询失败: "+err.Error()) c.cursorDetectJSONErr(500, 500, "查询失败: "+err.Error())

View File

@ -17,10 +17,16 @@ func Register() {
// 登录器使用激活码激活/续期 Cursor 设备(无需登录) // 登录器使用激活码激活/续期 Cursor 设备(无需登录)
beego.Router("/api/cursor/equipment/activateByCode", &controllers.ApiCursorEquipmentController{}, "post:ActivateByCode") beego.Router("/api/cursor/equipment/activateByCode", &controllers.ApiCursorEquipmentController{}, "post:ActivateByCode")
// Cursor Token 顺序读取/检测接口(无需登录,不改变号池状态) // Cursor Token 顺序读取/检测接口(无需登录,peek 不改变号池状态)
// GET /api/cursor/token/peek?id=11&data_type=tk // GET /api/cursor/token/peek?id=11&data_type=tk
beego.Router("/api/cursor/token/peek", &controllers.ApiCursorDetectController{}, "get:PeekToken") beego.Router("/api/cursor/token/peek", &controllers.ApiCursorDetectController{}, "get:PeekToken")
// Cursor Token 可用状态标记接口(无需登录)
// POST /api/cursor/token/available?id=11
// POST /api/cursor/token/unavailable?id=11
beego.Router("/api/cursor/token/available", &controllers.ApiCursorDetectController{}, "post:MarkTokenAvailable")
beego.Router("/api/cursor/token/unavailable", &controllers.ApiCursorDetectController{}, "post:MarkTokenUnavailable")
// 对外提卡接口(无需登录) // 对外提卡接口(无需登录)
// GET /api/getcard?type=xianyu&module=cursor&data_type=tk // GET /api/getcard?type=xianyu&module=cursor&data_type=tk
beego.Router("/api/getcard", &controllers.ApiGetCardController{}, "get:GetCard") beego.Router("/api/getcard", &controllers.ApiGetCardController{}, "get:GetCard")