Fix: unsafe pointer while initializing unfinished aria2 task

pull/247/head
HFO4 4 years ago
parent d30159579f
commit 7a6c84a115

@ -125,9 +125,10 @@ func Init() {
// 从数据库中读取未完成任务,创建监控 // 从数据库中读取未完成任务,创建监控
unfinished := model.GetDownloadsByStatus(Ready, Paused, Downloading) unfinished := model.GetDownloadsByStatus(Ready, Paused, Downloading)
for _, task := range unfinished {
for i := 0; i < len(unfinished); i++ {
// 创建任务监控 // 创建任务监控
NewMonitor(&task) NewMonitor(&unfinished[i])
} }
} }

@ -8,21 +8,23 @@ import (
// DownloadListResponse 下载列表响应条目 // DownloadListResponse 下载列表响应条目
type DownloadListResponse struct { type DownloadListResponse struct {
UpdateTime int64 `json:"update"` UpdateTime int64 `json:"update"`
Name string `json:"name"` UpdateInterval int `json:"interval"`
Status int `json:"status"` Name string `json:"name"`
UserID uint `json:"uid"` Status int `json:"status"`
Error string `json:"error"` UserID uint `json:"uid"`
Dst string `json:"dst"` Error string `json:"error"`
Total uint64 `json:"total"` Dst string `json:"dst"`
Downloaded uint64 `json:"downloaded"` Total uint64 `json:"total"`
Speed int `json:"speed"` Downloaded uint64 `json:"downloaded"`
Info rpc.StatusInfo `json:"info"` Speed int `json:"speed"`
Info rpc.StatusInfo `json:"info"`
} }
// BuildDownloadingResponse 构建正在下载的列表响应 // BuildDownloadingResponse 构建正在下载的列表响应
func BuildDownloadingResponse(tasks []model.Download) Response { func BuildDownloadingResponse(tasks []model.Download) Response {
resp := make([]DownloadListResponse, 0, len(tasks)) resp := make([]DownloadListResponse, 0, len(tasks))
interval := model.GetIntSetting("aria2_interval", 10)
for i := 0; i < len(tasks); i++ { for i := 0; i < len(tasks); i++ {
fileName := "" fileName := ""
@ -37,16 +39,17 @@ func BuildDownloadingResponse(tasks []model.Download) Response {
} }
resp = append(resp, DownloadListResponse{ resp = append(resp, DownloadListResponse{
UpdateTime: tasks[i].UpdatedAt.Unix(), UpdateTime: tasks[i].UpdatedAt.Unix(),
Name: fileName, UpdateInterval: interval,
Status: tasks[i].Status, Name: fileName,
UserID: tasks[i].UserID, Status: tasks[i].Status,
Error: tasks[i].Error, UserID: tasks[i].UserID,
Dst: tasks[i].Dst, Error: tasks[i].Error,
Total: tasks[i].TotalSize, Dst: tasks[i].Dst,
Downloaded: tasks[i].DownloadedSize, Total: tasks[i].TotalSize,
Speed: tasks[i].Speed, Downloaded: tasks[i].DownloadedSize,
Info: tasks[i].StatusInfo, Speed: tasks[i].Speed,
Info: tasks[i].StatusInfo,
}) })
} }

Loading…
Cancel
Save