dataRT/route/admin/command.go

58 lines
1.0 KiB
Go
Raw Normal View History

2025-11-06 21:09:50 +08:00
package admin
import (
"datart/data/postgres"
"datart/log"
"errors"
"fmt"
"github.com/gin-gonic/gin"
)
type command struct {
2025-11-20 20:58:51 +08:00
Command string `json:"command"`
Timeout int64 `json:"timeout"`
Args []any `json:"args"`
2025-11-06 21:09:50 +08:00
}
func (a *Admin) PostExecuteCommand(ctx *gin.Context) {
req, err := a.checkAndGenExecuteCommandRequest(ctx)
if err != nil {
log.Error(err)
ctx.JSON(200, gin.H{
"code": 1,
"msg": err.Error(),
})
return
}
err = postgres.GenSSU2ChannelSizes(ctx.Request.Context(), 500)
if err != nil {
log.Error(err, fmt.Sprintf(" params: %v", req))
ctx.JSON(200, gin.H{
"code": 2,
"msg": err.Error(),
})
return
}
ctx.JSON(200, gin.H{
"code": 0,
"msg": "success",
})
}
func (a *Admin) checkAndGenExecuteCommandRequest(ctx *gin.Context) (*command, error) {
req := new(command)
err := ctx.ShouldBindJSON(req)
if err != nil {
return req, errors.New("invalid body param")
}
2025-11-20 20:58:51 +08:00
if req.Command != "GenSSU2ChannelSizes" {
2025-12-05 17:54:25 +08:00
return nil, errors.New("invalid command")
2025-11-06 21:09:50 +08:00
}
return req, nil
}