alist/drivers/webdav/webdav.go

36 lines
877 B
Go
Raw Normal View History

2021-12-30 13:39:17 +00:00
package webdav
import (
"github.com/Xhofe/alist/drivers/base"
2022-04-04 12:55:22 +00:00
"github.com/Xhofe/alist/drivers/webdav/odrvcookie"
2021-12-30 13:39:17 +00:00
"github.com/Xhofe/alist/model"
2022-04-23 14:43:02 +00:00
"github.com/Xhofe/alist/pkg/gowebdav"
2021-12-30 13:39:17 +00:00
"github.com/Xhofe/alist/utils"
2022-04-04 12:55:22 +00:00
"net/http"
2021-12-30 13:39:17 +00:00
"strings"
)
func (driver WebDav) NewClient(account *model.Account) *gowebdav.Client {
2022-04-04 12:55:22 +00:00
c := gowebdav.NewClient(account.SiteUrl, account.Username, account.Password)
if isSharePoint(account) {
cookie, err := odrvcookie.GetCookie(account.Username, account.Password, account.SiteUrl)
if err == nil {
2022-04-04 12:55:22 +00:00
c.SetInterceptor(func(method string, rq *http.Request) {
rq.Header.Del("Authorization")
rq.Header.Set("Cookie", cookie)
2022-04-04 12:55:22 +00:00
})
}
}
return c
2021-12-30 13:39:17 +00:00
}
func (driver WebDav) WebDavPath(path string) string {
path = utils.ParsePath(path)
path = strings.TrimPrefix(path, "/")
return path
}
func init() {
base.RegisterDriver(&WebDav{})
}