Feat: cancel aria2 download task

This commit is contained in:
HFO4
2020-02-06 10:07:46 +08:00
parent 1a93c9a2b9
commit c29695a40d
5 changed files with 62 additions and 15 deletions

View File

@@ -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")