mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-09-20 04:36:09 +08:00

* Enable blank issue * chore(README.md): update docs (temporally) * Update FUNDING.yml * chore: purge README.md * chore: change module name to OpenListTeam/OpenList * fix: fix link errors * chore: remove v3 in module name * fix: resolve some conficts * fix: resolve conficts * docs: update with latest file --------- Co-authored-by: ShenLin <773933146@qq.com> Co-authored-by: Hantong Chen <cxwdyx620@gmail.com> Co-authored-by: joshua <i@joshua.su> Co-authored-by: Hantong Chen <70561268+cxw620@users.noreply.github.com>
53 lines
1.1 KiB
Go
53 lines
1.1 KiB
Go
package webdav
|
|
|
|
import (
|
|
"crypto/tls"
|
|
"net/http"
|
|
"net/http/cookiejar"
|
|
|
|
"github.com/OpenListTeam/OpenList/drivers/webdav/odrvcookie"
|
|
"github.com/OpenListTeam/OpenList/internal/model"
|
|
"github.com/OpenListTeam/OpenList/pkg/gowebdav"
|
|
)
|
|
|
|
// do others that not defined in Driver interface
|
|
|
|
func (d *WebDav) isSharepoint() bool {
|
|
return d.Vendor == "sharepoint"
|
|
}
|
|
|
|
func (d *WebDav) setClient() error {
|
|
c := gowebdav.NewClient(d.Address, d.Username, d.Password)
|
|
c.SetTransport(&http.Transport{
|
|
Proxy: http.ProxyFromEnvironment,
|
|
TLSClientConfig: &tls.Config{InsecureSkipVerify: d.TlsInsecureSkipVerify},
|
|
})
|
|
if d.isSharepoint() {
|
|
cookie, err := odrvcookie.GetCookie(d.Username, d.Password, d.Address)
|
|
if err == nil {
|
|
c.SetInterceptor(func(method string, rq *http.Request) {
|
|
rq.Header.Del("Authorization")
|
|
rq.Header.Set("Cookie", cookie)
|
|
})
|
|
} else {
|
|
return err
|
|
}
|
|
} else {
|
|
cookieJar, err := cookiejar.New(nil)
|
|
if err == nil {
|
|
c.SetJar(cookieJar)
|
|
} else {
|
|
return err
|
|
}
|
|
}
|
|
d.client = c
|
|
return nil
|
|
}
|
|
|
|
func getPath(obj model.Obj) string {
|
|
if obj.IsDir() {
|
|
return obj.GetPath() + "/"
|
|
}
|
|
return obj.GetPath()
|
|
}
|