diff --git a/assets b/assets index 691e828..88c1133 160000 --- a/assets +++ b/assets @@ -1 +1 @@ -Subproject commit 691e82868d69963d7620e758833ffdbcbf9936b5 +Subproject commit 88c1133306e2e9692b015db9aac57be20b269a53 diff --git a/pkg/serializer/aria2.go b/pkg/serializer/aria2.go index ce8fe63..1d6d3c6 100644 --- a/pkg/serializer/aria2.go +++ b/pkg/serializer/aria2.go @@ -76,9 +76,8 @@ func BuildFinishedListResponse(tasks []model.Download) Response { } // BuildDownloadingResponse 构建正在下载的列表响应 -func BuildDownloadingResponse(tasks []model.Download) Response { +func BuildDownloadingResponse(tasks []model.Download, intervals map[uint]int) Response { resp := make([]DownloadListResponse, 0, len(tasks)) - interval := model.GetIntSetting("aria2_interval", 10) for i := 0; i < len(tasks); i++ { fileName := "" @@ -92,6 +91,11 @@ func BuildDownloadingResponse(tasks []model.Download) Response { tasks[i].StatusInfo.Files[i2].Path = path.Base(tasks[i].StatusInfo.Files[i2].Path) } + interval := 10 + if actualInterval, ok := intervals[tasks[i].ID]; ok { + interval = actualInterval + } + resp = append(resp, DownloadListResponse{ UpdateTime: tasks[i].UpdatedAt, UpdateInterval: interval, diff --git a/pkg/serializer/aria2_test.go b/pkg/serializer/aria2_test.go index 48e7383..1f3ca61 100644 --- a/pkg/serializer/aria2_test.go +++ b/pkg/serializer/aria2_test.go @@ -82,10 +82,12 @@ func TestBuildDownloadingResponse(t *testing.T) { }, } tasks[1].StatusInfo.BitTorrent.Info.Name = "name.txt" + tasks[1].ID = 1 - res := BuildDownloadingResponse(tasks).Data.([]DownloadListResponse) + res := BuildDownloadingResponse(tasks, map[uint]int{1: 5}).Data.([]DownloadListResponse) asserts.Len(res, 2) asserts.Equal("name1.txt", res[1].Name) + asserts.Equal(5, res[1].UpdateInterval) asserts.Equal("name.txt", res[0].Name) asserts.Equal("name.txt", res[0].Info.Files[0].Path) asserts.Equal("name1.txt", res[1].Info.Files[0].Path) diff --git a/service/aria2/manage.go b/service/aria2/manage.go index f3ed47d..34e17b9 100644 --- a/service/aria2/manage.go +++ b/service/aria2/manage.go @@ -34,7 +34,16 @@ func (service *DownloadListService) Finished(c *gin.Context, user *model.User) s func (service *DownloadListService) Downloading(c *gin.Context, user *model.User) serializer.Response { // 查找下载记录 downloads := model.GetDownloadsByStatusAndUser(service.Page, user.ID, common.Downloading, common.Paused, common.Ready) - return serializer.BuildDownloadingResponse(downloads) + intervals := make(map[uint]int) + for _, 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 + } + } + } + + return serializer.BuildDownloadingResponse(downloads, intervals) } // Delete 取消或删除下载任务