feat(remote download): show download node in list page
This commit is contained in:
parent
7dda81368d
commit
f8ed4b4a5a
4 changed files with 19 additions and 2 deletions
2
assets
2
assets
|
@ -1 +1 @@
|
||||||
Subproject commit 2ca4a957a5f5e17f0c508b4212f27657a85ec0c9
|
Subproject commit dc81a86ae88b2f64a26bfc34918a22cd0be3429e
|
|
@ -32,6 +32,7 @@ type Download struct {
|
||||||
// 数据库忽略字段
|
// 数据库忽略字段
|
||||||
StatusInfo rpc.StatusInfo `gorm:"-"`
|
StatusInfo rpc.StatusInfo `gorm:"-"`
|
||||||
Task *Task `gorm:"-"`
|
Task *Task `gorm:"-"`
|
||||||
|
NodeName string `gorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AfterFind 找到下载任务后的钩子,处理Status结构
|
// AfterFind 找到下载任务后的钩子,处理Status结构
|
||||||
|
|
|
@ -19,6 +19,7 @@ type DownloadListResponse struct {
|
||||||
Downloaded uint64 `json:"downloaded"`
|
Downloaded uint64 `json:"downloaded"`
|
||||||
Speed int `json:"speed"`
|
Speed int `json:"speed"`
|
||||||
Info rpc.StatusInfo `json:"info"`
|
Info rpc.StatusInfo `json:"info"`
|
||||||
|
NodeName string `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FinishedListResponse 已完成任务条目
|
// FinishedListResponse 已完成任务条目
|
||||||
|
@ -34,6 +35,7 @@ type FinishedListResponse struct {
|
||||||
TaskError string `json:"task_error"`
|
TaskError string `json:"task_error"`
|
||||||
CreateTime time.Time `json:"create"`
|
CreateTime time.Time `json:"create"`
|
||||||
UpdateTime time.Time `json:"update"`
|
UpdateTime time.Time `json:"update"`
|
||||||
|
NodeName string `json:"node"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuildFinishedListResponse 构建已完成任务条目
|
// BuildFinishedListResponse 构建已完成任务条目
|
||||||
|
@ -62,6 +64,7 @@ func BuildFinishedListResponse(tasks []model.Download) Response {
|
||||||
TaskStatus: -1,
|
TaskStatus: -1,
|
||||||
UpdateTime: tasks[i].UpdatedAt,
|
UpdateTime: tasks[i].UpdatedAt,
|
||||||
CreateTime: tasks[i].CreatedAt,
|
CreateTime: tasks[i].CreatedAt,
|
||||||
|
NodeName: tasks[i].NodeName,
|
||||||
}
|
}
|
||||||
|
|
||||||
if tasks[i].Task != nil {
|
if tasks[i].Task != nil {
|
||||||
|
@ -106,6 +109,7 @@ func BuildDownloadingResponse(tasks []model.Download, intervals map[uint]int) Re
|
||||||
Downloaded: tasks[i].DownloadedSize,
|
Downloaded: tasks[i].DownloadedSize,
|
||||||
Speed: tasks[i].Speed,
|
Speed: tasks[i].Speed,
|
||||||
Info: tasks[i].StatusInfo,
|
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 {
|
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)
|
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)
|
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)
|
downloads := model.GetDownloadsByStatusAndUser(service.Page, user.ID, common.Downloading, common.Seeding, common.Paused, common.Ready)
|
||||||
intervals := make(map[uint]int)
|
intervals := make(map[uint]int)
|
||||||
for _, download := range downloads {
|
for key, download := range downloads {
|
||||||
if _, ok := intervals[download.ID]; !ok {
|
if _, ok := intervals[download.ID]; !ok {
|
||||||
if node := cluster.Default.GetNodeByID(download.GetNodeID()); node != nil {
|
if node := cluster.Default.GetNodeByID(download.GetNodeID()); node != nil {
|
||||||
intervals[download.ID] = node.DBModel().Aria2OptionsSerialized.Interval
|
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)
|
return serializer.BuildDownloadingResponse(downloads, intervals)
|
||||||
|
|
Loading…
Add table
Reference in a new issue