Fix: aria2 RPC retry / return NoT_FOUND error while listing not existed path

This commit is contained in:
HFO4
2020-02-10 10:33:39 +08:00
parent 7a6c84a115
commit f235ad1def
11 changed files with 125 additions and 16 deletions

View File

@@ -29,6 +29,7 @@ type Download struct {
// 数据库忽略字段
StatusInfo rpc.StatusInfo `gorm:"-"`
Task *Task `gorm:"-"`
}
// AfterFind 找到下载任务后的钩子处理Status结构
@@ -38,6 +39,10 @@ func (task *Download) AfterFind() (err error) {
err = json.Unmarshal([]byte(task.Attrs), &task.StatusInfo)
}
if task.TaskID != 0 {
task.Task, _ = GetTasksByID(task.TaskID)
}
return err
}
@@ -72,10 +77,15 @@ func GetDownloadsByStatus(status ...int) []Download {
}
// GetDownloadsByStatusAndUser 根据状态检索和用户ID下载
// page 为 0 表示列出所有,非零时分页
// TODO 测试
func GetDownloadsByStatusAndUser(uid uint, status ...int) []Download {
func GetDownloadsByStatusAndUser(page, uid uint, status ...int) []Download {
var tasks []Download
DB.Where("user_id = ? and status in (?)", uid, status).Find(&tasks)
dbChain := DB
if page > 0 {
dbChain = dbChain.Limit(10).Offset((page - 1) * 10).Order("updated_at DESC")
}
dbChain.Where("user_id = ? and status in (?)", uid, status).Find(&tasks)
return tasks
}

View File

@@ -41,8 +41,16 @@ func (task *Task) SetError(err string) error {
}
// GetTasksByStatus 根据状态检索任务
func GetTasksByStatus(status int) []Task {
func GetTasksByStatus(status ...int) []Task {
var tasks []Task
DB.Where("status = ?", status).Find(&tasks)
DB.Where("status in (?)", status).Find(&tasks)
return tasks
}
// GetTasksByID 根据ID检索任务
// TODO 测试
func GetTasksByID(id interface{}) (*Task, error) {
task := &Task{}
result := DB.Where("id = ?", id).First(task)
return task, result.Error
}