fix(webdav): sharepoint repeat login

pull/992/head
Xhofe 2022-04-24 15:37:59 +08:00
parent 27b7dae113
commit e4df146043
1 changed files with 4 additions and 1 deletions

View File

@ -2,6 +2,7 @@ package odrvcookie
import ( import (
"github.com/Xhofe/alist/utils/cookie" "github.com/Xhofe/alist/utils/cookie"
log "github.com/sirupsen/logrus"
"net/http" "net/http"
"sync" "sync"
"time" "time"
@ -13,7 +14,7 @@ type SpCookie struct {
} }
func (sp SpCookie) IsExpire() bool { func (sp SpCookie) IsExpire() bool {
return time.Now().Before(sp.expire) return time.Now().After(sp.expire)
} }
var cookiesMap = struct { var cookiesMap = struct {
@ -27,9 +28,11 @@ func GetCookie(username, password, siteUrl string) (string, error) {
spCookie, ok := cookiesMap.m[username] spCookie, ok := cookiesMap.m[username]
if ok { if ok {
if !spCookie.IsExpire() { if !spCookie.IsExpire() {
log.Debugln("sp use old cookie.")
return spCookie.Cookie, nil return spCookie.Cookie, nil
} }
} }
log.Debugln("fetch new cookie")
ca := New(username, password, siteUrl) ca := New(username, password, siteUrl)
tokenConf, err := ca.Cookies() tokenConf, err := ca.Cookies()
if err != nil { if err != nil {