You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
1.1 KiB
60 lines
1.1 KiB
package crontab
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/cast"
|
|
"tools/logic/orm"
|
|
)
|
|
|
|
func Add(ctx *gin.Context) {
|
|
taskId := ctx.PostForm("id")
|
|
name := ctx.PostForm("name")
|
|
cron := ctx.PostForm("cron")
|
|
url := ctx.PostForm("url")
|
|
desc := ctx.PostForm("desc")
|
|
author := ctx.PostForm("author")
|
|
task := &Crontab{
|
|
TaskId: cast.ToInt64(taskId),
|
|
Cron: cron,
|
|
Url: url,
|
|
Name: name,
|
|
Desc: desc,
|
|
Author: author,
|
|
Status: 1,
|
|
}
|
|
add(task)
|
|
ctx.JSON(200, nil)
|
|
}
|
|
func GetAll(ctx *gin.Context) {
|
|
ctx.JSON(200, orm.GetAll[*Crontab]())
|
|
}
|
|
|
|
func Get(ctx *gin.Context) {
|
|
taskId := ctx.Request.URL.Query().Get("task_id")
|
|
task := orm.Get[*Crontab](cast.ToInt64(taskId))
|
|
if task != nil {
|
|
ctx.JSON(200, task)
|
|
}
|
|
}
|
|
|
|
func Modify(ctx *gin.Context) {
|
|
taskId := ctx.Request.URL.Query().Get("task_id")
|
|
op := ctx.Request.URL.Query().Get("op")
|
|
task := orm.Get[*Crontab](cast.ToInt64(taskId))
|
|
if task == nil {
|
|
return
|
|
}
|
|
switch op {
|
|
case "open":
|
|
task.open()
|
|
break
|
|
case "close":
|
|
task.Stop()
|
|
break
|
|
case "delete":
|
|
task.delete()
|
|
ReStart()
|
|
break
|
|
}
|
|
ctx.JSON(200, nil)
|
|
}
|
|
|