mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Fix: aria2 RPC retry / return NoT_FOUND error while listing not existed path
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user