mirror of https://github.com/Xhofe/alist
fix(webdav): sharepoint repeat login
parent
27b7dae113
commit
e4df146043
|
@ -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 {
|
||||||
|
|
Loading…
Reference in New Issue