Fix: refresh interval not working

This commit is contained in:
HFO4
2021-11-30 19:26:35 +08:00
parent af4d9767c2
commit 84d81f201f
4 changed files with 20 additions and 5 deletions

View File

@@ -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,

View File

@@ -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)