feat(remote download): show download node in list page

pull/1519/head
HFO4 2 years ago
parent 7dda81368d
commit f8ed4b4a5a

@ -1 +1 @@
Subproject commit 2ca4a957a5f5e17f0c508b4212f27657a85ec0c9
Subproject commit dc81a86ae88b2f64a26bfc34918a22cd0be3429e

@ -32,6 +32,7 @@ type Download struct {
// 数据库忽略字段
StatusInfo rpc.StatusInfo `gorm:"-"`
Task *Task `gorm:"-"`
NodeName string `gorm:"-"`
}
// AfterFind 找到下载任务后的钩子处理Status结构

@ -19,6 +19,7 @@ type DownloadListResponse struct {
Downloaded uint64 `json:"downloaded"`
Speed int `json:"speed"`
Info rpc.StatusInfo `json:"info"`
NodeName string `json:"node"`
}
// FinishedListResponse 已完成任务条目
@ -34,6 +35,7 @@ type FinishedListResponse struct {
TaskError string `json:"task_error"`
CreateTime time.Time `json:"create"`
UpdateTime time.Time `json:"update"`
NodeName string `json:"node"`
}
// BuildFinishedListResponse 构建已完成任务条目
@ -62,6 +64,7 @@ func BuildFinishedListResponse(tasks []model.Download) Response {
TaskStatus: -1,
UpdateTime: tasks[i].UpdatedAt,
CreateTime: tasks[i].CreatedAt,
NodeName: tasks[i].NodeName,
}
if tasks[i].Task != nil {
@ -106,6 +109,7 @@ func BuildDownloadingResponse(tasks []model.Download, intervals map[uint]int) Re
Downloaded: tasks[i].DownloadedSize,
Speed: tasks[i].Speed,
Info: tasks[i].StatusInfo,
NodeName: tasks[i].NodeName,
})
}

@ -27,6 +27,13 @@ type DownloadListService struct {
func (service *DownloadListService) Finished(c *gin.Context, user *model.User) serializer.Response {
// 查找下载记录
downloads := model.GetDownloadsByStatusAndUser(service.Page, user.ID, common.Error, common.Complete, common.Canceled, common.Unknown)
for key, download := range downloads {
node := cluster.Default.GetNodeByID(download.GetNodeID())
if node != nil {
downloads[key].NodeName = node.DBModel().Name
}
}
return serializer.BuildFinishedListResponse(downloads)
}
@ -35,12 +42,17 @@ func (service *DownloadListService) Downloading(c *gin.Context, user *model.User
// 查找下载记录
downloads := model.GetDownloadsByStatusAndUser(service.Page, user.ID, common.Downloading, common.Seeding, common.Paused, common.Ready)
intervals := make(map[uint]int)
for _, download := range downloads {
for key, download := range downloads {
if _, ok := intervals[download.ID]; !ok {
if node := cluster.Default.GetNodeByID(download.GetNodeID()); node != nil {
intervals[download.ID] = node.DBModel().Aria2OptionsSerialized.Interval
}
}
node := cluster.Default.GetNodeByID(download.GetNodeID())
if node != nil {
downloads[key].NodeName = node.DBModel().Name
}
}
return serializer.BuildDownloadingResponse(downloads, intervals)

Loading…
Cancel
Save