mirror of
https://github.com/halejohn/Cloudreve.git
synced 2026-01-26 09:34:57 +08:00
Feat: list downloading file
This commit is contained in:
@@ -39,7 +39,15 @@ func (client *RPCService) Init(server, secret string, timeout int, options []int
|
||||
|
||||
// Status 查询下载状态
|
||||
func (client *RPCService) Status(task *model.Download) (rpc.StatusInfo, error) {
|
||||
return client.caller.TellStatus(task.GID)
|
||||
res, err := client.caller.TellStatus(task.GID)
|
||||
if err != nil {
|
||||
// 失败后重试
|
||||
util.Log().Debug("无法获取离线下载状态,%s,10秒钟后重试", err)
|
||||
time.Sleep(time.Duration(10) * time.Second)
|
||||
res, err = client.caller.TellStatus(task.GID)
|
||||
}
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// Cancel 取消下载
|
||||
|
||||
54
pkg/serializer/aria2.go
Normal file
54
pkg/serializer/aria2.go
Normal file
@@ -0,0 +1,54 @@
|
||||
package serializer
|
||||
|
||||
import (
|
||||
model "github.com/HFO4/cloudreve/models"
|
||||
"github.com/zyxar/argo/rpc"
|
||||
"path"
|
||||
)
|
||||
|
||||
// DownloadListResponse 下载列表响应条目
|
||||
type DownloadListResponse struct {
|
||||
UpdateTime int64 `json:"update"`
|
||||
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"`
|
||||
Speed int `json:"speed"`
|
||||
Info rpc.StatusInfo `json:"info"`
|
||||
}
|
||||
|
||||
// BuildDownloadingResponse 构建正在下载的列表响应
|
||||
func BuildDownloadingResponse(tasks []model.Download) Response {
|
||||
resp := make([]DownloadListResponse, 0, len(tasks))
|
||||
|
||||
for i := 0; i < len(tasks); i++ {
|
||||
fileName := ""
|
||||
if len(tasks[i].StatusInfo.Files) > 0 {
|
||||
fileName = path.Base(tasks[i].StatusInfo.Files[0].Path)
|
||||
}
|
||||
|
||||
// 过滤敏感信息
|
||||
tasks[i].StatusInfo.Dir = ""
|
||||
for i2 := 0; i2 < len(tasks[i].StatusInfo.Files); i2++ {
|
||||
tasks[i].StatusInfo.Files[i2].Path = path.Base(tasks[i].StatusInfo.Files[i2].Path)
|
||||
}
|
||||
|
||||
resp = append(resp, DownloadListResponse{
|
||||
UpdateTime: tasks[i].UpdatedAt.Unix(),
|
||||
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,
|
||||
Speed: tasks[i].Speed,
|
||||
Info: tasks[i].StatusInfo,
|
||||
})
|
||||
}
|
||||
|
||||
return Response{Data: resp}
|
||||
}
|
||||
Reference in New Issue
Block a user