更新获取接口
This commit is contained in:
parent
ccad4c05f7
commit
53decd0084
@ -34,13 +34,14 @@ var validModules = map[string]bool{
|
||||
|
||||
func (c *ApiGetCardController) cardErr(httpStatus, code int, msg string) {
|
||||
c.Ctx.Output.SetStatus(httpStatus)
|
||||
c.Data["json"] = map[string]interface{}{"code": code, "msg": msg}
|
||||
_ = c.ServeJSON()
|
||||
c.Ctx.Output.Header("Content-Type", "text/plain; charset=utf-8")
|
||||
_ = c.Ctx.Output.Body([]byte(msg))
|
||||
}
|
||||
|
||||
func (c *ApiGetCardController) cardOK(data interface{}) {
|
||||
c.Data["json"] = map[string]interface{}{"code": 200, "msg": "success", "data": data}
|
||||
_ = c.ServeJSON()
|
||||
func (c *ApiGetCardController) cardOK(text string) {
|
||||
c.Ctx.Output.SetStatus(200)
|
||||
c.Ctx.Output.Header("Content-Type", "text/plain; charset=utf-8")
|
||||
_ = c.Ctx.Output.Body([]byte(text))
|
||||
}
|
||||
|
||||
// GetCard 提取一张卡(不可重复提取)
|
||||
@ -179,11 +180,8 @@ func (c *ApiGetCardController) extractKrio(platform, dataType string, now time.T
|
||||
c.cardOK(buildCardResult(&row.Account, &row.Password, row.Token, row.DataType))
|
||||
}
|
||||
|
||||
// buildCardResult 根据账号类型组装返回数据
|
||||
func buildCardResult(account, password *string, token string, dataType string) map[string]interface{} {
|
||||
result := map[string]interface{}{
|
||||
"type": dataType,
|
||||
}
|
||||
// buildCardResult 根据账号类型返回格式化字符串
|
||||
func buildCardResult(account, password *string, token string, dataType string) string {
|
||||
acc := ""
|
||||
pwd := ""
|
||||
if account != nil {
|
||||
@ -194,14 +192,10 @@ func buildCardResult(account, password *string, token string, dataType string) m
|
||||
}
|
||||
switch dataType {
|
||||
case "account":
|
||||
result["account"] = acc
|
||||
result["password"] = pwd
|
||||
case "tk":
|
||||
result["token"] = token
|
||||
return fmt.Sprintf("账号:%s / 密码:%s", acc, pwd)
|
||||
case "account_tk":
|
||||
result["account"] = acc
|
||||
result["password"] = pwd
|
||||
result["token"] = token
|
||||
return fmt.Sprintf("账号:%s / 密码:%s / Token:%s", acc, pwd, token)
|
||||
default: // tk
|
||||
return token
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@ -95,50 +95,88 @@ func listPoolRows(c *beego.Controller, module string) {
|
||||
dataType := strings.TrimSpace(c.GetString("type"))
|
||||
status := strings.TrimSpace(c.GetString("status"))
|
||||
|
||||
var table string
|
||||
applyFilters := func(qs orm.QuerySeter) orm.QuerySeter {
|
||||
if dataType != "" && isValidPoolType(dataType) {
|
||||
qs = qs.Filter("data_type", dataType)
|
||||
}
|
||||
if status == "unused" {
|
||||
qs = qs.Filter("is_extracted", 0)
|
||||
}
|
||||
if status == "extracted" {
|
||||
qs = qs.Filter("is_extracted", 1)
|
||||
}
|
||||
if keyword != "" {
|
||||
qs = qs.Filter("account__icontains", keyword)
|
||||
}
|
||||
return qs
|
||||
}
|
||||
|
||||
var list interface{}
|
||||
var total int64
|
||||
var err error
|
||||
|
||||
switch module {
|
||||
case "cursor":
|
||||
table = new(models.PlatformAccountPoolCursor).TableName()
|
||||
qs := applyFilters(models.Orm.QueryTable(new(models.PlatformAccountPoolCursor)))
|
||||
total, err = qs.Count()
|
||||
if err != nil {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
var rows []models.PlatformAccountPoolCursor
|
||||
_, err = qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
poolJSONErr(c, 500, 500, "cursor查询失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if rows == nil {
|
||||
rows = []models.PlatformAccountPoolCursor{}
|
||||
}
|
||||
list = rows
|
||||
case "windsurf":
|
||||
table = new(models.PlatformAccountPoolWindsurf).TableName()
|
||||
qs := applyFilters(models.Orm.QueryTable(new(models.PlatformAccountPoolWindsurf)))
|
||||
total, err = qs.Count()
|
||||
if err != nil {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
var rows []models.PlatformAccountPoolWindsurf
|
||||
_, err = qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if rows == nil {
|
||||
rows = []models.PlatformAccountPoolWindsurf{}
|
||||
}
|
||||
list = rows
|
||||
case "krio":
|
||||
table = new(models.PlatformAccountPoolKiro).TableName()
|
||||
qs := applyFilters(models.Orm.QueryTable(new(models.PlatformAccountPoolKiro)))
|
||||
total, err = qs.Count()
|
||||
if err != nil {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
var rows []models.PlatformAccountPoolKiro
|
||||
_, err = qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).All(&rows)
|
||||
if err != nil && err != orm.ErrNoRows {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
if rows == nil {
|
||||
rows = []models.PlatformAccountPoolKiro{}
|
||||
}
|
||||
list = rows
|
||||
default:
|
||||
poolJSONErr(c, 400, 400, "无效模块")
|
||||
return
|
||||
}
|
||||
|
||||
qs := models.Orm.QueryTable(table)
|
||||
if dataType != "" && isValidPoolType(dataType) {
|
||||
qs = qs.Filter("data_type", dataType)
|
||||
}
|
||||
if status == "unused" {
|
||||
qs = qs.Filter("is_extracted", 0)
|
||||
}
|
||||
if status == "extracted" {
|
||||
qs = qs.Filter("is_extracted", 1)
|
||||
}
|
||||
if keyword != "" {
|
||||
qs = qs.Filter("account__icontains", keyword).Filter("remark__icontains", keyword)
|
||||
}
|
||||
total, err := qs.Count()
|
||||
if err != nil {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
var rows []orm.Params
|
||||
_, err = qs.OrderBy("-id").Limit(pageSize, (page-1)*pageSize).Values(&rows)
|
||||
if err != nil {
|
||||
poolJSONErr(c, 500, 500, "获取列表失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
c.Data["json"] = map[string]interface{}{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"data": map[string]interface{}{
|
||||
"list": rows,
|
||||
"list": list,
|
||||
"total": total,
|
||||
},
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user