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:
@@ -23,6 +23,7 @@ type Monitor struct {
|
||||
Interval time.Duration
|
||||
|
||||
notifier chan StatusEvent
|
||||
retried int
|
||||
}
|
||||
|
||||
// StatusEvent 状态改变事件
|
||||
@@ -68,11 +69,20 @@ func (monitor *Monitor) Loop() {
|
||||
func (monitor *Monitor) Update() bool {
|
||||
status, err := Instance.Status(monitor.Task)
|
||||
if err != nil {
|
||||
monitor.retried++
|
||||
util.Log().Warning("无法获取下载任务[%s]的状态,%s", monitor.Task.GID, err)
|
||||
monitor.setErrorStatus(err)
|
||||
monitor.RemoveTempFolder()
|
||||
return true
|
||||
|
||||
// 十次重试后认定为任务失败
|
||||
if monitor.retried > 10 {
|
||||
util.Log().Warning("无法获取下载任务[%s]的状态,超过最大重试次数限制,%s", monitor.Task.GID, err)
|
||||
monitor.setErrorStatus(err)
|
||||
monitor.RemoveTempFolder()
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
monitor.retried = 0
|
||||
|
||||
// 磁力链下载需要跟随
|
||||
if len(status.FollowedBy) > 0 {
|
||||
|
||||
@@ -253,9 +253,8 @@ func (fs *FileSystem) ListDeleteFiles(ctx context.Context, ids []uint) error {
|
||||
func (fs *FileSystem) List(ctx context.Context, dirPath string, pathProcessor func(string) string) ([]Object, error) {
|
||||
// 获取父目录
|
||||
isExist, folder := fs.IsPathExist(dirPath)
|
||||
// 不存在时返回空的结果
|
||||
if !isExist {
|
||||
return []Object{}, nil
|
||||
return nil, ErrPathNotExist
|
||||
}
|
||||
fs.SetTargetDir(&[]model.Folder{*folder})
|
||||
|
||||
|
||||
@@ -12,8 +12,6 @@ type DownloadListResponse struct {
|
||||
UpdateInterval int `json:"interval"`
|
||||
Name string `json:"name"`
|
||||
Status int `json:"status"`
|
||||
UserID uint `json:"uid"`
|
||||
Error string `json:"error"`
|
||||
Dst string `json:"dst"`
|
||||
Total uint64 `json:"total"`
|
||||
Downloaded uint64 `json:"downloaded"`
|
||||
@@ -21,6 +19,58 @@ type DownloadListResponse struct {
|
||||
Info rpc.StatusInfo `json:"info"`
|
||||
}
|
||||
|
||||
// FinishedListResponse 已完成任务条目
|
||||
type FinishedListResponse struct {
|
||||
Name string `json:"name"`
|
||||
Status int `json:"status"`
|
||||
Dst string `json:"dst"`
|
||||
Error string `json:"error"`
|
||||
Total uint64 `json:"total"`
|
||||
Files []rpc.FileInfo `json:"files"`
|
||||
TaskStatus int `json:"task_status"`
|
||||
TaskError string `json:"task_error"`
|
||||
CreateTime string `json:"create"`
|
||||
UpdateTime string `json:"update"`
|
||||
}
|
||||
|
||||
// BuildFinishedListResponse 构建已完成任务条目
|
||||
func BuildFinishedListResponse(tasks []model.Download) Response {
|
||||
resp := make([]FinishedListResponse, 0, len(tasks))
|
||||
|
||||
for i := 0; i < len(tasks); i++ {
|
||||
fileName := tasks[i].StatusInfo.BitTorrent.Info.Name
|
||||
if len(tasks[i].StatusInfo.Files) == 1 {
|
||||
fileName = path.Base(tasks[i].StatusInfo.Files[0].Path)
|
||||
}
|
||||
|
||||
// 过滤敏感信息
|
||||
for i2 := 0; i2 < len(tasks[i].StatusInfo.Files); i2++ {
|
||||
tasks[i].StatusInfo.Files[i2].Path = path.Base(tasks[i].StatusInfo.Files[i2].Path)
|
||||
}
|
||||
|
||||
download := FinishedListResponse{
|
||||
Name: fileName,
|
||||
Status: tasks[i].Status,
|
||||
Error: tasks[i].Error,
|
||||
Dst: tasks[i].Dst,
|
||||
Total: tasks[i].TotalSize,
|
||||
Files: tasks[i].StatusInfo.Files,
|
||||
TaskStatus: -1,
|
||||
UpdateTime: tasks[i].UpdatedAt.Format("2006-01-02 15:04:05"),
|
||||
CreateTime: tasks[i].CreatedAt.Format("2006-01-02 15:04:05"),
|
||||
}
|
||||
|
||||
if tasks[i].Task != nil {
|
||||
download.TaskError = tasks[i].Task.Error
|
||||
download.TaskStatus = tasks[i].Task.Status
|
||||
}
|
||||
|
||||
resp = append(resp, download)
|
||||
}
|
||||
|
||||
return Response{Data: resp}
|
||||
}
|
||||
|
||||
// BuildDownloadingResponse 构建正在下载的列表响应
|
||||
func BuildDownloadingResponse(tasks []model.Download) Response {
|
||||
resp := make([]DownloadListResponse, 0, len(tasks))
|
||||
@@ -43,8 +93,6 @@ func BuildDownloadingResponse(tasks []model.Download) Response {
|
||||
UpdateInterval: interval,
|
||||
Name: fileName,
|
||||
Status: tasks[i].Status,
|
||||
UserID: tasks[i].UserID,
|
||||
Error: tasks[i].Error,
|
||||
Dst: tasks[i].Dst,
|
||||
Total: tasks[i].TotalSize,
|
||||
Downloaded: tasks[i].DownloadedSize,
|
||||
|
||||
@@ -77,7 +77,7 @@ func Record(job Job) (*model.Task, error) {
|
||||
|
||||
// Resume 从数据库中恢复未完成任务
|
||||
func Resume() {
|
||||
tasks := model.GetTasksByStatus(Queued)
|
||||
tasks := model.GetTasksByStatus(Queued, Processing)
|
||||
if len(tasks) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user