mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-02 21:27:15 +08:00
fix web api client issue
This commit is contained in:
parent
4a623b443c
commit
787aa53ce7
@ -79,7 +79,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunAlbumList()
|
||||
@ -107,7 +107,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunAlbumCreate(c.Args().Get(0), c.Args().Get(1))
|
||||
@ -136,7 +136,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunAlbumDelete(c.Args())
|
||||
@ -162,7 +162,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunAlbumRename(c.Args().Get(0), c.Args().Get(1))
|
||||
@ -188,7 +188,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunAlbumListFile(c.Args().Get(0))
|
||||
@ -214,7 +214,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
subArgs := c.Args()
|
||||
@ -248,7 +248,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
subArgs := c.Args()
|
||||
@ -280,7 +280,7 @@ func CmdAlbum() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
subArgs := c.Args()
|
||||
|
@ -66,7 +66,7 @@ func CmdRecycle() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunRecycleList(parseDriveId(c))
|
||||
@ -92,7 +92,7 @@ func CmdRecycle() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
if c.NArg() <= 0 {
|
||||
@ -122,7 +122,7 @@ func CmdRecycle() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
if c.Bool("all") {
|
||||
|
@ -54,7 +54,7 @@ func CmdSave() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunSave(parseDriveId(c), c.Args()...)
|
||||
|
@ -74,7 +74,7 @@ func CmdShare() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
et := ""
|
||||
@ -152,7 +152,7 @@ func CmdShare() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
RunShareList()
|
||||
@ -172,7 +172,7 @@ func CmdShare() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
if c.NArg() < 1 {
|
||||
@ -203,7 +203,7 @@ func CmdShare() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
if c.NArg() < 1 {
|
||||
|
@ -146,8 +146,8 @@ func RefreshTokenInNeed(activeUser *config.PanUser, deviceName string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// refresh expired token
|
||||
if activeUser.PanClient() != nil {
|
||||
// refresh expired web token
|
||||
if activeUser.PanClient().WebapiPanClient() != nil {
|
||||
if len(activeUser.WebapiToken.AccessToken) > 0 {
|
||||
cz := time.FixedZone("CST", 8*3600) // 东8区
|
||||
expiredTime := time.Unix(activeUser.WebapiToken.Expired, 0).In(cz)
|
||||
@ -164,7 +164,7 @@ func RefreshTokenInNeed(activeUser *config.PanUser, deviceName string) bool {
|
||||
}
|
||||
|
||||
// need update refresh token
|
||||
logger.Verboseln("access token expired, get new from server")
|
||||
logger.Verboseln("web access token expired, get new from server")
|
||||
loginHelper := panlogin.NewLoginHelper(config.DefaultTokenServiceWebHost)
|
||||
wt, e := loginHelper.GetWebapiNewToken(activeUser.TicketId, activeUser.UserId)
|
||||
if e != nil {
|
||||
|
@ -56,7 +56,7 @@ func CmdXcp() cli.Command {
|
||||
return nil
|
||||
}
|
||||
if config.Config.ActiveUser().PanClient().WebapiPanClient() == nil {
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用")
|
||||
fmt.Println("WEB客户端未登录,请登录后再使用该命令")
|
||||
return nil
|
||||
}
|
||||
srcDriveId := parseDriveId(c)
|
||||
|
@ -29,3 +29,8 @@ func (p *PanClient) WebapiPanClient() *aliyunpan.PanClient {
|
||||
func (p *PanClient) OpenapiPanClient() *aliyunpan_open.OpenPanClient {
|
||||
return p.openapiPanClient
|
||||
}
|
||||
|
||||
func (p *PanClient) UpdateClient(openClient *aliyunpan_open.OpenPanClient, webClient *aliyunpan.PanClient) {
|
||||
p.webapiPanClient = webClient
|
||||
p.openapiPanClient = openClient
|
||||
}
|
||||
|
@ -456,6 +456,7 @@ func (c *PanConfig) SetActiveUser(user *PanUser) *PanUser {
|
||||
u.WebapiToken = user.WebapiToken
|
||||
u.OpenapiToken = user.OpenapiToken
|
||||
u.TicketId = user.TicketId
|
||||
u.PanClient().UpdateClient(user.PanClient().OpenapiPanClient(), user.PanClient().WebapiPanClient())
|
||||
needToInsert = false
|
||||
break
|
||||
}
|
||||
|
@ -153,14 +153,19 @@ doOpenLoginAct:
|
||||
AccessToken: wt.AccessToken,
|
||||
Expired: wt.Expired,
|
||||
}
|
||||
goto doOpenLoginAct
|
||||
}
|
||||
time.Sleep(time.Duration(1) * time.Second)
|
||||
goto doOpenLoginAct
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
doWebLoginAct:
|
||||
// setup webapi client
|
||||
var webUserInfo *aliyunpan.UserInfo
|
||||
var err2 *apierror.ApiError
|
||||
var webPanClient *aliyunpan.PanClient
|
||||
if webapiToken != nil && webapiToken.AccessToken != "" {
|
||||
appConfig := aliyunpan.AppConfig{
|
||||
AppId: "25dzX3vbYqktVxyX",
|
||||
DeviceId: deviceId,
|
||||
@ -168,7 +173,7 @@ doWebLoginAct:
|
||||
Nonce: 0,
|
||||
PublicKey: "",
|
||||
}
|
||||
webPanClient := aliyunpan.NewPanClient(aliyunpan.WebLoginToken{
|
||||
webPanClient = aliyunpan.NewPanClient(aliyunpan.WebLoginToken{
|
||||
AccessTokenType: "Bearer",
|
||||
AccessToken: webapiToken.AccessToken,
|
||||
RefreshToken: "",
|
||||
@ -180,7 +185,7 @@ doWebLoginAct:
|
||||
})
|
||||
// web api token maybe expired
|
||||
// check & refresh new one
|
||||
webUserInfo, err2 := webPanClient.GetUserInfo()
|
||||
webUserInfo, err2 = webPanClient.GetUserInfo()
|
||||
if err2 != nil {
|
||||
if err2.Code == apierror.ApiCodeTokenExpiredCode && tryRefreshWebToken {
|
||||
tryRefreshWebToken = false
|
||||
@ -193,13 +198,15 @@ doWebLoginAct:
|
||||
AccessToken: wt.AccessToken,
|
||||
Expired: wt.Expired,
|
||||
}
|
||||
}
|
||||
time.Sleep(time.Duration(1) * time.Second)
|
||||
goto doWebLoginAct
|
||||
}
|
||||
webPanClient = nil
|
||||
//return nil, err2
|
||||
}
|
||||
return nil, err2
|
||||
}
|
||||
|
||||
// web create session
|
||||
if webUserInfo != nil {
|
||||
appConfig.UserId = webUserInfo.UserId
|
||||
webPanClient.UpdateAppConfig(appConfig)
|
||||
r, e := webPanClient.CreateSession(nil)
|
||||
@ -209,6 +216,8 @@ doWebLoginAct:
|
||||
if r != nil && !r.Result {
|
||||
logger.Verboseln("上传签名秘钥失败,可能是你账号登录的设备已超最大数量")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// setup PanUser
|
||||
@ -226,7 +235,9 @@ doWebLoginAct:
|
||||
if openUserInfo != nil {
|
||||
// fill userId for client
|
||||
u.PanClient().OpenapiPanClient().UpdateUserId(openUserInfo.UserId)
|
||||
if u.PanClient().WebapiPanClient() != nil {
|
||||
u.PanClient().WebapiPanClient().UpdateUserId(openUserInfo.UserId)
|
||||
}
|
||||
|
||||
// update user
|
||||
if openUserInfo.Nickname != "" {
|
||||
|
Loading…
Reference in New Issue
Block a user