Feat: handle aria2 download complete

This commit is contained in:
HFO4
2020-02-05 11:22:19 +08:00
parent fe8f1b1ef5
commit 8c7e3883ee
10 changed files with 536 additions and 25 deletions

View File

@@ -8,17 +8,20 @@ import (
// Download 离线下载队列模型
type Download struct {
gorm.Model
Status int // 任务状态
Type int // 任务类型
Source string // 文件下载地址
Name string // 任务文件名
Size uint64 // 文件大小
GID string // 任务ID
Path string `gorm:"type:text"` // 存储路径
Attrs string `gorm:"type:text"` // 任务状态属性
FolderID uint // 存储目录ID
UserID uint // 发起者UID
TaskID uint // 对应的转存任务ID
Status int // 任务状态
Type int // 任务类型
Source string // 文件下载地址
TotalSize uint64 // 文件大小
DownloadedSize uint64 // 文件大小
GID string // 任务ID
Speed int // 下载速度
Path string `gorm:"type:text"` // 存储路径
Parent string `gorm:"type:text"` // 存储目录
Attrs string `gorm:"type:text"` // 任务状态属性
Error string `gorm:"type:text"` // 错误描述
Dst string `gorm:"type:text"` // 用户文件系统存储父目录路径
UserID uint // 发起者UID
TaskID uint // 对应的转存任务ID
}
// Create 创建离线下载记录
@@ -29,3 +32,19 @@ func (task *Download) Create() (uint, error) {
}
return task.ID, nil
}
// Save 更新
func (task *Download) Save() error {
if err := DB.Save(task).Error; err != nil {
util.Log().Warning("无法更新离线下载记录, %s", err)
return err
}
return nil
}
// GetDownloadsByStatus 根据状态检索下载
func GetDownloadsByStatus(status ...int) []Download {
var tasks []Download
DB.Where("status in (?)", status).Find(&tasks)
return tasks
}

View File

@@ -159,8 +159,9 @@ Neue',Helvetica,Arial,sans-serif; box-sizing: border-box; font-size: 14px; verti
{Name: "header", Value: `X-Sendfile`, Type: "download"},
{Name: "aria2_token", Value: `your token`, Type: "aria2"},
{Name: "aria2_token", Value: `your token`, Type: "aria2"},
{Name: "aria2_temp_path", Value: `F:\aria2-1.33.1-win-64bit-build1\temp`, Type: "aria2"},
{Name: "aria2_temp_path", Value: ``, Type: "aria2"},
{Name: "aria2_options", Value: `{"max-tries":5}`, Type: "aria2"},
{Name: "aria2_interval", Value: `10`, Type: "aria2"},
{Name: "max_worker_num", Value: `10`, Type: "task"},
{Name: "max_parallel_transfer", Value: `4`, Type: "task"},
{Name: "secret_key", Value: util.RandStringRunes(256), Type: "auth"},