forked from MartialBE/one-hub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask.go
64 lines (54 loc) · 1.26 KB
/
task.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package controller
import (
"net/http"
"one-api/common"
"one-api/model"
"regexp"
"github.com/gin-gonic/gin"
"gorm.io/datatypes"
)
func GetAllTask(c *gin.Context) {
var params model.TaskQueryParams
if err := c.ShouldBindQuery(¶ms); err != nil {
common.APIRespondWithError(c, http.StatusOK, err)
return
}
tasks, err := model.GetAllTasks(¶ms)
if err != nil {
common.APIRespondWithError(c, http.StatusOK, err)
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": tasks,
})
}
func GetUserAllTask(c *gin.Context) {
userId := c.GetInt("id")
var params model.TaskQueryParams
if err := c.ShouldBindQuery(¶ms); err != nil {
common.APIRespondWithError(c, http.StatusOK, err)
return
}
tasks, err := model.GetAllUserTasks(userId, ¶ms)
if err != nil {
common.APIRespondWithError(c, http.StatusOK, err)
return
}
re := regexp.MustCompile(`"user_id":\s*"[^"]*",?\s*`)
for _, task := range *tasks.Data {
if task.Platform == model.TaskPlatformSuno && task.Action == "MUSIC" {
data := task.Data.String()
if data != "" {
data = re.ReplaceAllString(data, "")
task.Data = datatypes.JSON(data)
}
}
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": tasks,
})
}