Feat: handle aria2 download complete

This commit is contained in:
HFO4
2020-02-05 11:22:19 +08:00
parent fe8f1b1ef5
commit 8c7e3883ee
10 changed files with 536 additions and 25 deletions

View File

@@ -30,11 +30,16 @@ func (client *RPCService) Init(server, secret string, timeout int, options []int
Options: options,
}
caller, err := rpc.New(context.Background(), server, secret, time.Duration(timeout)*time.Second,
rpc.DummyNotifier{})
EventNotifier)
client.caller = caller
return err
}
// Status 查询下载状态
func (client *RPCService) Status(task *model.Download) (rpc.StatusInfo, error) {
return client.caller.TellStatus(task.GID)
}
// CreateTask 创建新任务
func (client *RPCService) CreateTask(task *model.Download) error {
// 生成存储路径
@@ -45,7 +50,11 @@ func (client *RPCService) CreateTask(task *model.Download) error {
)
// 创建下载任务
gid, err := client.caller.AddURI(task.Source, map[string]string{"dir": task.Path})
options := []interface{}{map[string]string{"dir": task.Path}}
if len(client.options.Options) > 0 {
options = append(options, client.options.Options)
}
gid, err := client.caller.AddURI(task.Source, options...)
if err != nil || gid == "" {
return err
}
@@ -53,6 +62,12 @@ func (client *RPCService) CreateTask(task *model.Download) error {
// 保存到数据库
task.GID = gid
_, err = task.Create()
if err != nil {
return err
}
return err
// 创建任务监控
NewMonitor(task)
return nil
}