Skip to content

Commit

Permalink
改善COOKIE更新策略,启用定时检测,失效再刷新
Browse files Browse the repository at this point in the history
  • Loading branch information
libsgh committed Jun 18, 2021
1 parent 2a5a6ab commit aa9cd70
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
13 changes: 13 additions & 0 deletions Util/Cloud189.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,19 @@ func Cloud189Login(accountId, user, password string) string {
return ""
}

func Cloud189IsLogin(accountId string) bool {
CLoud189Session := CLoud189Sessions[accountId]
if _, ok := CLoud189Sessions[accountId]; ok {
resp, err := CLoud189Session.Get("https://cloud.189.cn/v2/getLoginedInfos.action?showPC=true", nil)
if err == nil && resp.Text != "" && jsoniter.Valid(resp.Bytes) && jsoniter.Get(resp.Bytes, "errorMsg").ToString() == "" {
return true
} else {
log.Debug(resp.Text)
}
}
return false
}

//分享链接跳转下载
func Cloud189shareToDown(url, passCode, fileId, subFileId string) string {
CLoud189Session := nic.Session{}
Expand Down
20 changes: 19 additions & 1 deletion Util/Teambition.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,25 @@ func TeambitionProUpload(server, accountId, parentId string, files []*multipart.
}
return true
}

func TeambitionIsLogin(accountId string, isUs bool) bool {
if _, ok := TeambitionSessions[accountId]; ok {
TeambitionSession := TeambitionSessions[accountId].TeambitionSession
d := ""
if isUs {
d = "us-"
}
resp, _ := TeambitionSession.Get(fmt.Sprintf("https://%saccount.teambition.com/api/account", d), nil)
if resp.StatusCode == 401 {
return false
} else if resp.StatusCode == 200 {
id := jsoniter.Get(resp.Bytes, "_id").ToString()
if id != "" {
return true
}
}
}
return false
}
func UTCTimeFormat(timeStr string) string {
t, _ := time.Parse(time.RFC3339, timeStr)
timeUint := t.In(time.Local).Unix()
Expand Down
2 changes: 1 addition & 1 deletion entity/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type Config struct {
type Account struct {
Id string `json:"id"` //网盘空间id
Name string `json:"name"` //网盘空间名称
Mode string `json:"mode"` //网盘模式,native(本地模式),cloud189(默认,天翼云网盘),teambition(阿里teambition网盘)
Mode string `json:"mode"` //网盘模式,native(本地模式),cloud189(默认,天翼云网盘),teambition(阿里teambition网盘),aliyundrive
User string `json:"user"` //网盘账号用户名,邮箱或手机号
Password string `json:"password"` //网盘账号密码
RefreshToken string `json:"refresh_token"` //刷新token
Expand Down
28 changes: 26 additions & 2 deletions jobs/Jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,30 @@ func Run() {
Util.AliRefreshToken(account)
}
})
//cookie有效性检测
c.AddFunc("0 0/1 * * * ?", func() {
for _, account := range config.GloablConfig.Accounts {
if account.Mode != "native" || account.Mode != "aliyundrive" {
cookieValid := true
if account.Mode == "cloud189" {
cookieValid = Util.Cloud189IsLogin(account.Id)
}
if account.Mode == "teambition" {
cookieValid = Util.TeambitionIsLogin(account.Id, false)
}
if account.Mode == "teambition-us" {
cookieValid = Util.TeambitionIsLogin(account.Id, true)
}
if cookieValid == false {
log.Infof("[COOKIE定时检查][%s]>>%s>>失效", account.Name, account.Mode)
log.Infof("开始刷新[%s]的COOKIE...", account.Name)
AccountLogin(account)
} else {
log.Debugf("[COOKIE定时检查][%s]>>%s>>有效", account.Name, account.Mode)
}
}
}
})
c.Start()
}
func StartInit() {
Expand Down Expand Up @@ -101,10 +125,10 @@ func AccountLogin(account entity.Account) {
msg = "[" + account.Name + "] >> 本地模式"
}
if cookie != "" {
log.Infoln(msg + " >> cookie更新 >> 登录成功")
log.Infoln(msg + " >> COOKIE更新 >> 登录成功")
model.SqliteDb.Table("account").Where("id=?", account.Id).Update("cookie_status", 2)
} else if cookie == "" && account.Mode != "native" {
log.Infoln(msg + "cookie更新 >> 登录失败,请检查用户名,密码(token)是否正确")
log.Infoln(msg + "COOKIE更新 >> 登录失败,请检查用户名,密码(token)是否正确")
model.SqliteDb.Table("account").Where("id=?", account.Id).Update("cookie_status", 3)
}
}
Expand Down

0 comments on commit aa9cd70

Please sign in to comment.