mirror of https://github.com/Xhofe/alist
chore: add version to aria handle
parent
b1d563c874
commit
4ac312fd07
|
@ -15,24 +15,24 @@ var DownTaskManager = task.NewTaskManager[string](3)
|
|||
var notify = NewNotify()
|
||||
var client rpc.Client
|
||||
|
||||
func InitClient(timeout int) error {
|
||||
func InitClient(timeout int) (string, error) {
|
||||
uri := setting.GetByKey(conf.Aria2Uri)
|
||||
secret := setting.GetByKey(conf.Aria2Secret)
|
||||
return InitAria2Client(uri, secret, timeout)
|
||||
}
|
||||
|
||||
func InitAria2Client(uri string, secret string, timeout int) error {
|
||||
func InitAria2Client(uri string, secret string, timeout int) (string, error) {
|
||||
c, err := rpc.New(context.Background(), uri, secret, time.Duration(timeout)*time.Second, notify)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to init aria2 client")
|
||||
return "", errors.Wrap(err, "failed to init aria2 client")
|
||||
}
|
||||
version, err := c.GetVersion()
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "failed get aria2 version")
|
||||
return "", errors.Wrapf(err, "failed get aria2 version")
|
||||
}
|
||||
client = c
|
||||
log.Infof("using aria2 version: %s", version.Version)
|
||||
return nil
|
||||
return version.Version, nil
|
||||
}
|
||||
|
||||
func IsAria2Ready() bool {
|
||||
|
|
|
@ -7,7 +7,7 @@ import (
|
|||
|
||||
func InitAria2() {
|
||||
go func() {
|
||||
err := aria2.InitClient(2)
|
||||
_, err := aria2.InitClient(2)
|
||||
log.Errorf("failed to init aria2 client: %+v", err)
|
||||
}()
|
||||
}
|
||||
|
|
|
@ -29,12 +29,12 @@ func SetAria2(c *gin.Context) {
|
|||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
err := aria2.InitClient(2)
|
||||
version, err := aria2.InitClient(2)
|
||||
if err != nil {
|
||||
common.ErrorResp(c, err, 500)
|
||||
return
|
||||
}
|
||||
common.SuccessResp(c)
|
||||
common.SuccessResp(c, version)
|
||||
}
|
||||
|
||||
type AddAria2Req struct {
|
||||
|
|
Loading…
Reference in New Issue