feat: add task info to resp of add task api (close #5579)
This commit is contained in:
@ -3,6 +3,7 @@ package handles
|
||||
import (
|
||||
"github.com/alist-org/alist/v3/internal/fs"
|
||||
"github.com/alist-org/alist/v3/internal/offline_download/tool"
|
||||
"github.com/alist-org/alist/v3/pkg/utils"
|
||||
"github.com/alist-org/alist/v3/server/common"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/xhofe/tache"
|
||||
@ -33,11 +34,7 @@ func getTaskInfo[T tache.TaskWithInfo](task T) TaskInfo {
|
||||
}
|
||||
|
||||
func getTaskInfos[T tache.TaskWithInfo](tasks []T) []TaskInfo {
|
||||
var infos []TaskInfo
|
||||
for _, t := range tasks {
|
||||
infos = append(infos, getTaskInfo(t))
|
||||
}
|
||||
return infos
|
||||
return utils.MustSliceConvert(tasks, getTaskInfo[T])
|
||||
}
|
||||
|
||||
func taskRoute[T tache.TaskWithInfo](g *gin.RouterGroup, manager *tache.Manager[T]) {
|
||||
@ -48,6 +45,15 @@ func taskRoute[T tache.TaskWithInfo](g *gin.RouterGroup, manager *tache.Manager[
|
||||
g.GET("/done", func(c *gin.Context) {
|
||||
common.SuccessResp(c, getTaskInfos(manager.GetByState(tache.StateCanceled, tache.StateFailed, tache.StateSucceeded)))
|
||||
})
|
||||
g.POST("/info", func(c *gin.Context) {
|
||||
tid := c.Query("tid")
|
||||
task, ok := manager.GetByID(tid)
|
||||
if !ok {
|
||||
common.ErrorStrResp(c, "task not found", 404)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c, getTaskInfo(task))
|
||||
})
|
||||
g.POST("/cancel", func(c *gin.Context) {
|
||||
tid := c.Query("tid")
|
||||
manager.Cancel(tid)
|
||||
|
Reference in New Issue
Block a user