alist/internal/aria2/aria2.go

27 lines
579 B
Go
Raw Normal View History

2022-06-20 12:34:58 +00:00
package aria2
import (
"context"
"github.com/alist-org/alist/v3/pkg/aria2/rpc"
"github.com/alist-org/alist/v3/pkg/task"
"github.com/pkg/errors"
"time"
)
2022-06-22 11:28:41 +00:00
var TaskManager = task.NewTaskManager[string](3)
2022-06-20 14:29:52 +00:00
var notify = NewNotify()
2022-06-20 12:34:58 +00:00
var client rpc.Client
func InitAria2Client(uri string, secret string, timeout int) error {
2022-06-20 14:29:52 +00:00
c, err := rpc.New(context.Background(), uri, secret, time.Duration(timeout)*time.Second, notify)
2022-06-20 12:34:58 +00:00
if err != nil {
return errors.Wrap(err, "failed to init aria2 client")
}
client = c
return nil
}
func IsAria2Ready() bool {
return client != nil
}