diff --git a/drivers/115/meta.go b/drivers/115/meta.go index a17135510ec..cdb7b3685dc 100644 --- a/drivers/115/meta.go +++ b/drivers/115/meta.go @@ -6,7 +6,8 @@ import ( ) type Addition struct { - Cookie string `json:"cookie" required:"true"` + Cookie string `json:"cookie"` + QRCodeToken string `json:"qrcode_token"` driver.RootID } diff --git a/drivers/115/util.go b/drivers/115/util.go index fbde8919b36..fad12bb06a1 100644 --- a/drivers/115/util.go +++ b/drivers/115/util.go @@ -1,23 +1,36 @@ package _115 import ( + "fmt" + "github.com/SheltonZhu/115driver/pkg/driver" - "github.com/alist-org/alist/v3/drivers/base" + "github.com/pkg/errors" ) func (d *Pan115) login() error { + var err error opts := []driver.Option{ - driver.WithRestyClient(base.RestyClient), driver.UA("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/106.0.0.0 Safari/537.36 115Browser/23.9.3.2 115disk/30.1.0"), } - d.client = driver.New(opts...) - cr := &driver.Credential{} - if err := cr.FromCookie(d.Addition.Cookie); err != nil { - return err + if d.Addition.QRCodeToken != "" { + s := &driver.QRCodeSession{ + UID: d.Addition.QRCodeToken, + } + if cr, err = d.client.QRCodeLogin(s); err != nil { + return errors.Wrap(err, "failed to login by qrcode") + } + d.Addition.Cookie = fmt.Sprintf("UID=%s;CID=%s;SEID=%s", cr.UID, cr.CID, cr.SEID) + d.Addition.QRCodeToken = "" + } else if d.Addition.Cookie != "" { + if err = cr.FromCookie(d.Addition.Cookie); err != nil { + return errors.Wrap(err, "failed to login by cookies") + } + d.client.ImportCredential(cr) + } else { + return errors.New("missing cookie or qrcode account") } - d.client.ImportCredential(cr) return d.client.LoginCheck() } diff --git a/go.mod b/go.mod index e1928056f51..66f26689c59 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/alist-org/alist/v3 go 1.19 require ( - github.com/SheltonZhu/115driver v1.0.9 + github.com/SheltonZhu/115driver v1.0.11 github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a github.com/aws/aws-sdk-go v1.44.88 github.com/caarlos0/env/v6 v6.9.3 @@ -71,6 +71,7 @@ require ( github.com/orzogc/fake115uploader v0.3.3-0.20221009101310-08b764073b77 // indirect github.com/pelletier/go-toml/v2 v2.0.1 // indirect github.com/pierrec/lz4/v4 v4.1.17 // indirect + github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/ugorji/go/codec v1.2.7 // indirect golang.org/x/image v0.0.0-20220722155232-062f8c9fd539 // indirect diff --git a/go.sum b/go.sum index a7b04a0ba6f..3419ba99dfe 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver/v3 v3.1.1 h1:hLg3sBzpNErnxhQtUy/mmLR2I9foDujNK030IGemrRc= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= -github.com/SheltonZhu/115driver v1.0.9 h1:QlSgsrbmwiFB74L3z5NCsHBjAFKlwmOShGiD9qinXBc= -github.com/SheltonZhu/115driver v1.0.9/go.mod h1:Xv7lKJ3BXyc+vU5YfymXHG8e/QTopRawSHwk09K7RRw= +github.com/SheltonZhu/115driver v1.0.11 h1:DIZ4Iun5kZEfrcjdAy14qSfWFarxVlJHP7K+pdvXcCY= +github.com/SheltonZhu/115driver v1.0.11/go.mod h1:00ixivHH5HqDj4S7kAWbkuUrjtsJTxc7cGv5RMw3RVs= github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a h1:RenIAa2q4H8UcS/cqmwdT1WCWIAH5aumP8m8RpbqVsE= github.com/Xhofe/go-cache v0.0.0-20220723083548-714439c8af9a/go.mod h1:sSBbaOg90XwWKtpT56kVujF0bIeVITnPlssLclogS04= github.com/aead/ecdh v0.2.0 h1:pYop54xVaq/CEREFEcukHRZfTdjiWvYIsZDXXrBapQQ= @@ -221,6 +221,8 @@ github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMB github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE= github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0= +github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M= github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU= github.com/spf13/cobra v1.5.0/go.mod h1:dWXEIy2H428czQCjInthrTRUg7yKbok+2Qi/yBIJoUM= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=