mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 17:41:57 +08:00
Feat: cancel aria2 download task
This commit is contained in:
@@ -12,6 +12,34 @@ type SelectFileService struct {
|
||||
Indexes []int `json:"indexes" binding:"required"`
|
||||
}
|
||||
|
||||
// DownloadTaskService 下载任务管理服务
|
||||
type DownloadTaskService struct {
|
||||
GID string `uri:"gid" binding:"required"`
|
||||
}
|
||||
|
||||
// Delete 取消下载任务
|
||||
func (service *DownloadTaskService) Delete(c *gin.Context) serializer.Response {
|
||||
userCtx, _ := c.Get("user")
|
||||
user := userCtx.(*model.User)
|
||||
|
||||
// 查找下载记录
|
||||
download, err := model.GetDownloadByGid(c.Param("gid"), user.ID)
|
||||
if err != nil {
|
||||
return serializer.Err(serializer.CodeNotFound, "下载记录不存在", err)
|
||||
}
|
||||
|
||||
if download.Status != aria2.Downloading && download.Status != aria2.Paused {
|
||||
return serializer.Err(serializer.CodeNoPermissionErr, "此下载任务无法取消", err)
|
||||
}
|
||||
|
||||
// 取消任务
|
||||
if err := aria2.Instance.Cancel(download); err != nil {
|
||||
return serializer.Err(serializer.CodeNotSet, "操作失败", err)
|
||||
}
|
||||
|
||||
return serializer.Response{}
|
||||
}
|
||||
|
||||
// Select 选取要下载的文件
|
||||
func (service *SelectFileService) Select(c *gin.Context) serializer.Response {
|
||||
userCtx, _ := c.Get("user")
|
||||
|
||||
Reference in New Issue
Block a user