Feat: validate / cancel task while downloading file in aria2

This commit is contained in:
HFO4
2020-02-05 12:58:26 +08:00
parent 8c7e3883ee
commit 3ed84ad5ec
7 changed files with 119 additions and 4 deletions

View File

@@ -22,6 +22,9 @@ type Download struct {
Dst string `gorm:"type:text"` // 用户文件系统存储父目录路径
UserID uint // 发起者UID
TaskID uint // 对应的转存任务ID
// 关联模型
User *User `gorm:"PRELOAD:false,association_autoupdate:false"`
}
// Create 创建离线下载记录
@@ -48,3 +51,13 @@ func GetDownloadsByStatus(status ...int) []Download {
DB.Where("status in (?)", status).Find(&tasks)
return tasks
}
// GetOwner 获取下载任务所属用户
func (task *Download) GetOwner() *User {
if task.User == nil {
if user, err := GetUserByID(task.UserID); err == nil {
return &user
}
}
return task.User
}

View File

@@ -12,7 +12,7 @@ type Task struct {
Type int // 任务类型
UserID uint // 发起者UID0表示为系统发起
Progress int // 进度
Error string // 错误信息
Error string `gorm:"type:text"` // 错误信息
Props string `gorm:"type:text"` // 任务属性
}