增加便捷工具
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
type PlatformAccountPoolCursorController struct{ beego.Controller }
|
||||
type PlatformAccountPoolWindsurfController struct{ beego.Controller }
|
||||
type PlatformAccountPoolKrioController struct{ beego.Controller }
|
||||
type PlatformAccountPoolCodexController struct{ beego.Controller }
|
||||
|
||||
type accountPoolCreateRow struct {
|
||||
DataType string `json:"type"`
|
||||
@@ -265,6 +266,28 @@ func listPoolRows(c *beego.Controller, module string) {
|
||||
rows = []models.PlatformAccountPoolKiro{}
|
||||
}
|
||||
list = rows
|
||||
case "codex":
|
||||
table := (&models.PlatformAccountPoolCodex{}).TableName()
|
||||
total, err = accountPoolCountMySQL(table, where, whereArgs)
|
||||
if err != nil {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
sqlStr := fmt.Sprintf(
|
||||
"SELECT * FROM `%s` WHERE %s ORDER BY FIELD(is_extracted, 0, 2, 3, 1) ASC, id DESC LIMIT ? OFFSET ?",
|
||||
table, where,
|
||||
)
|
||||
args := append(append([]interface{}{}, whereArgs...), pageSize, offset)
|
||||
var rows []models.PlatformAccountPoolCodex
|
||||
_, err = models.Orm.Raw(sqlStr, args...).QueryRows(&rows)
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if rows == nil {
|
||||
rows = []models.PlatformAccountPoolCodex{}
|
||||
}
|
||||
list = rows
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -332,6 +355,16 @@ func addPoolRow(c *beego.Controller, module string) {
|
||||
IsExtracted: 0,
|
||||
}
|
||||
_, err = models.Orm.Insert(r)
|
||||
case "codex":
|
||||
r := &models.PlatformAccountPoolCodex{
|
||||
DataType: strings.TrimSpace(row.DataType),
|
||||
Account: strings.TrimSpace(row.Account),
|
||||
Password: strings.TrimSpace(row.Password),
|
||||
Token: strings.TrimSpace(row.Token),
|
||||
Remark: strings.TrimSpace(row.Remark),
|
||||
IsExtracted: 0,
|
||||
}
|
||||
_, err = models.Orm.Insert(r)
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -397,6 +430,15 @@ func batchAddPoolRows(c *beego.Controller, module string) {
|
||||
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),
|
||||
Password: strings.TrimSpace(row.Password),
|
||||
Token: strings.TrimSpace(row.Token),
|
||||
Remark: strings.TrimSpace(row.Remark),
|
||||
IsExtracted: 0,
|
||||
})
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -443,6 +485,13 @@ func getPoolDetail(c *beego.Controller, module string) {
|
||||
return
|
||||
}
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": row}
|
||||
case "codex":
|
||||
var row models.PlatformAccountPoolCodex
|
||||
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("id", id).One(&row); err != nil {
|
||||
poolJSONErr(c, 404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": row}
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -573,6 +622,34 @@ func extractPoolRow(c *beego.Controller, module string) {
|
||||
row.ExtractedPlatform = &pf
|
||||
row.Remark = remark
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "提取成功", "data": row}
|
||||
case "codex":
|
||||
var row models.PlatformAccountPoolCodex
|
||||
qs := models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("is_extracted", 0)
|
||||
if payload.ID > 0 {
|
||||
qs = qs.Filter("id", payload.ID)
|
||||
} else if payload.Type != "" {
|
||||
qs = qs.Filter("data_type", payload.Type)
|
||||
}
|
||||
if err := qs.OrderBy("id").One(&row); err != nil {
|
||||
poolJSONErr(c, 404, 404, "没有可提取数据")
|
||||
return
|
||||
}
|
||||
_, err = models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("id", row.ID).Update(map[string]interface{}{
|
||||
"is_extracted": extractStatus,
|
||||
"extracted_time": now,
|
||||
"extracted_platform": platform,
|
||||
"remark": remark,
|
||||
})
|
||||
if err != nil {
|
||||
poolJSONErr(c, 500, 500, "提取失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
row.IsExtracted = extractStatus
|
||||
row.ExtractedTime = &now
|
||||
pf := platform
|
||||
row.ExtractedPlatform = &pf
|
||||
row.Remark = remark
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "提取成功", "data": row}
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -678,6 +755,22 @@ func replenishWithProbe(c *beego.Controller, module, dataType, platform, remark
|
||||
id: row.ID, dataType: row.DataType, token: row.Token, row: row,
|
||||
}, nil
|
||||
}
|
||||
case "codex":
|
||||
fetch = func() (*poolReplenishCandidate, error) {
|
||||
var row models.PlatformAccountPoolCodex
|
||||
err := models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).
|
||||
Filter("is_extracted", 0).
|
||||
Filter("data_type", dataType).
|
||||
Filter("delete_time__isnull", true).
|
||||
OrderBy("id").
|
||||
One(&row)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &poolReplenishCandidate{
|
||||
id: row.ID, dataType: row.DataType, token: row.Token, row: row,
|
||||
}, nil
|
||||
}
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -754,6 +847,12 @@ func replenishApplyResponse(row interface{}, platform, remark string, now time.T
|
||||
r.ExtractedPlatform = &pf
|
||||
r.Remark = remark
|
||||
return r
|
||||
case models.PlatformAccountPoolCodex:
|
||||
r.IsExtracted = 2
|
||||
r.ExtractedTime = &now
|
||||
r.ExtractedPlatform = &pf
|
||||
r.Remark = remark
|
||||
return r
|
||||
default:
|
||||
return row
|
||||
}
|
||||
@@ -793,6 +892,10 @@ func updatePoolRemark(c *beego.Controller, module string) {
|
||||
updated, err = models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).Filter("id", payload.ID).Update(map[string]interface{}{
|
||||
"remark": remark,
|
||||
})
|
||||
case "codex":
|
||||
updated, err = models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("id", payload.ID).Update(map[string]interface{}{
|
||||
"remark": remark,
|
||||
})
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -826,6 +929,8 @@ func updatePoolExtractFields(module string, id uint64, fields map[string]interfa
|
||||
return models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)).Filter("id", id).Update(fields)
|
||||
case "krio":
|
||||
return models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)).Filter("id", id).Update(fields)
|
||||
case "codex":
|
||||
return models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("id", id).Update(fields)
|
||||
default:
|
||||
return 0, fmt.Errorf("无效模块")
|
||||
}
|
||||
@@ -1059,6 +1164,17 @@ func probePoolToken(c *beego.Controller, module string) {
|
||||
return
|
||||
}
|
||||
token = strings.TrimSpace(row.Token)
|
||||
case "codex":
|
||||
if payload.ID == 0 {
|
||||
poolJSONErr(c, 400, 400, "缺少有效 id")
|
||||
return
|
||||
}
|
||||
var row models.PlatformAccountPoolCodex
|
||||
if err := models.Orm.QueryTable(new(models.PlatformAccountPoolCodex)).Filter("id", payload.ID).One(&row); err != nil {
|
||||
poolJSONErr(c, 404, 404, "记录不存在")
|
||||
return
|
||||
}
|
||||
token = strings.TrimSpace(row.Token)
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
@@ -1182,3 +1298,21 @@ func (c *PlatformAccountPoolKrioController) UpdatePlatform() {
|
||||
}
|
||||
func (c *PlatformAccountPoolKrioController) Unextract() { unextractPoolRow(&c.Controller, "krio") }
|
||||
func (c *PlatformAccountPoolKrioController) ProbeToken() { probePoolToken(&c.Controller, "krio") }
|
||||
|
||||
func (c *PlatformAccountPoolCodexController) List() { listPoolRows(&c.Controller, "codex") }
|
||||
func (c *PlatformAccountPoolCodexController) Add() { addPoolRow(&c.Controller, "codex") }
|
||||
func (c *PlatformAccountPoolCodexController) BatchAdd() { batchAddPoolRows(&c.Controller, "codex") }
|
||||
func (c *PlatformAccountPoolCodexController) Detail() { getPoolDetail(&c.Controller, "codex") }
|
||||
func (c *PlatformAccountPoolCodexController) Extract() { extractPoolRow(&c.Controller, "codex") }
|
||||
func (c *PlatformAccountPoolCodexController) Replenish() { replenishPoolRow(&c.Controller, "codex") }
|
||||
func (c *PlatformAccountPoolCodexController) UpdateRemark() {
|
||||
updatePoolRemark(&c.Controller, "codex")
|
||||
}
|
||||
func (c *PlatformAccountPoolCodexController) SetUnavailable() {
|
||||
setPoolUnavailable(&c.Controller, "codex")
|
||||
}
|
||||
func (c *PlatformAccountPoolCodexController) UpdatePlatform() {
|
||||
updatePoolPlatform(&c.Controller, "codex")
|
||||
}
|
||||
func (c *PlatformAccountPoolCodexController) Unextract() { unextractPoolRow(&c.Controller, "codex") }
|
||||
func (c *PlatformAccountPoolCodexController) ProbeToken() { probePoolToken(&c.Controller, "codex") }
|
||||
|
||||
Reference in New Issue
Block a user