mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-03 14:11:47 +01:00
🎨 S3/WebDAV 数据同步支持设置超时时间 Fix https://github.com/siyuan-note/siyuan/issues/6781
This commit is contained in:
parent
4629e15f57
commit
faa2d2d655
9 changed files with 72 additions and 7 deletions
|
|
@ -46,6 +46,7 @@ type S3 struct {
|
|||
Region string `json:"region"` // 存储区域
|
||||
PathStyle bool `json:"pathStyle"` // 是否使用路径风格
|
||||
SkipTlsVerify bool `json:"skipTlsVerify"` // 是否跳过 TLS 验证
|
||||
Timeout int `json:"timeout"` // 超时时间,单位:秒
|
||||
}
|
||||
|
||||
type WebDAV struct {
|
||||
|
|
@ -53,6 +54,7 @@ type WebDAV struct {
|
|||
Username string `json:"username"` // 用户名
|
||||
Password string `json:"password"` // 密码
|
||||
SkipTlsVerify bool `json:"skipTlsVerify"` // 是否跳过 TLS 验证
|
||||
Timeout int `json:"timeout"` // 超时时间,单位:秒
|
||||
}
|
||||
|
||||
const (
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ require (
|
|||
github.com/panjf2000/ants/v2 v2.6.0
|
||||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/radovskyb/watcher v1.0.7
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221204024701-250a4fc841d1
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221204123650-c456e15f08bd
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
|
||||
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
|
||||
github.com/siyuan-note/filelock v0.0.0-20221117095924-e1947438a35e
|
||||
|
|
@ -126,7 +126,8 @@ require (
|
|||
|
||||
replace github.com/mattn/go-sqlite3 => github.com/88250/go-sqlite3 v1.14.13-0.20220714142610-fbbda1ee84f5
|
||||
|
||||
//replace github.com/siyuan-note/dejavu => D:\88250\dejavu
|
||||
replace github.com/siyuan-note/dejavu => D:\88250\dejavu
|
||||
|
||||
//replace github.com/siyuan-note/httpclient => D:\88250\httpclient
|
||||
//replace github.com/siyuan-note/filelock => D:\88250\filelock
|
||||
//replace github.com/88250/lute => D:\gogogo\src\github.com\88250\lute
|
||||
|
|
|
|||
|
|
@ -359,8 +359,6 @@ github.com/shurcooL/reactions v0.0.0-20181006231557-f2e0b4ca5b82/go.mod h1:TCR1l
|
|||
github.com/shurcooL/sanitized_anchor_name v0.0.0-20170918181015-86672fcb3f95/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDaXHZDBsXlPCDqdhQuJkuw4NOtaxYe3xii4=
|
||||
github.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221204024701-250a4fc841d1 h1:fyR9Y+DUEctHBMu7uq8VWWrMv5tgYP1hWChNYa2pLmQ=
|
||||
github.com/siyuan-note/dejavu v0.0.0-20221204024701-250a4fc841d1/go.mod h1:YKJSOrRHSJ9Fdkx37e2+8e/fJGrW1xU71hXmlH2ybzA=
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=
|
||||
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=
|
||||
|
|
|
|||
|
|
@ -246,10 +246,12 @@ func InitConf() {
|
|||
Conf.Sync.S3 = &conf.S3{}
|
||||
}
|
||||
Conf.Sync.S3.Endpoint = util.NormalizeEndpoint(Conf.Sync.S3.Endpoint)
|
||||
Conf.Sync.S3.Timeout = util.NormalizeTimeout(Conf.Sync.S3.Timeout)
|
||||
if nil == Conf.Sync.WebDAV {
|
||||
Conf.Sync.WebDAV = &conf.WebDAV{}
|
||||
}
|
||||
Conf.Sync.WebDAV.Endpoint = util.NormalizeEndpoint(Conf.Sync.WebDAV.Endpoint)
|
||||
Conf.Sync.WebDAV.Timeout = util.NormalizeTimeout(Conf.Sync.WebDAV.Timeout)
|
||||
|
||||
if nil == Conf.Api {
|
||||
Conf.Api = conf.NewAPI()
|
||||
|
|
|
|||
|
|
@ -824,7 +824,7 @@ func newRepository() (ret *dejavu.Repo, err error) {
|
|||
cloudRepo = cloud.NewSiYuan(&cloud.BaseCloud{Conf: cloudConf})
|
||||
case conf.ProviderS3:
|
||||
s3HTTPClient := &http.Client{Transport: util.NewTransport(cloudConf.S3.SkipTlsVerify)}
|
||||
s3HTTPClient.Timeout = 30 * time.Second
|
||||
s3HTTPClient.Timeout = time.Duration(cloudConf.S3.Timeout) * time.Second
|
||||
cloudRepo = cloud.NewS3(&cloud.BaseCloud{Conf: cloudConf}, s3HTTPClient)
|
||||
case conf.ProviderWebDAV:
|
||||
webdavClient := gowebdav.NewClient(cloudConf.WebDAV.Endpoint, cloudConf.WebDAV.Username, cloudConf.WebDAV.Password)
|
||||
|
|
@ -832,7 +832,7 @@ func newRepository() (ret *dejavu.Repo, err error) {
|
|||
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
|
||||
webdavClient.SetHeader("Authorization", auth)
|
||||
webdavClient.SetHeader("User-Agent", util.UserAgent)
|
||||
webdavClient.SetTimeout(30 * time.Second)
|
||||
webdavClient.SetTimeout(time.Duration(cloudConf.WebDAV.Timeout) * time.Second)
|
||||
webdavClient.SetTransport(util.NewTransport(cloudConf.WebDAV.SkipTlsVerify))
|
||||
cloudRepo = cloud.NewWebDAV(&cloud.BaseCloud{Conf: cloudConf}, webdavClient)
|
||||
default:
|
||||
|
|
@ -1056,6 +1056,7 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
|
|||
Region: Conf.Sync.S3.Region,
|
||||
PathStyle: Conf.Sync.S3.PathStyle,
|
||||
SkipTlsVerify: Conf.Sync.S3.SkipTlsVerify,
|
||||
Timeout: Conf.Sync.S3.Timeout,
|
||||
}
|
||||
case conf.ProviderWebDAV:
|
||||
ret.WebDAV = &cloud.ConfWebDAV{
|
||||
|
|
@ -1063,6 +1064,7 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
|
|||
Username: Conf.Sync.WebDAV.Username,
|
||||
Password: Conf.Sync.WebDAV.Password,
|
||||
SkipTlsVerify: Conf.Sync.WebDAV.SkipTlsVerify,
|
||||
Timeout: Conf.Sync.WebDAV.Timeout,
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("invalid provider [%d]", Conf.Sync.Provider)
|
||||
|
|
|
|||
|
|
@ -320,6 +320,7 @@ func SetSyncProviderS3(s3 *conf.S3) (err error) {
|
|||
s3.SecretKey = strings.TrimSpace(s3.SecretKey)
|
||||
s3.Bucket = strings.TrimSpace(s3.Bucket)
|
||||
s3.Region = strings.TrimSpace(s3.Region)
|
||||
s3.Timeout = util.NormalizeTimeout(s3.Timeout)
|
||||
|
||||
Conf.Sync.S3 = s3
|
||||
Conf.Save()
|
||||
|
|
@ -334,6 +335,7 @@ func SetSyncProviderWebDAV(webdav *conf.WebDAV) (err error) {
|
|||
webdav.Endpoint = util.NormalizeEndpoint(webdav.Endpoint)
|
||||
webdav.Username = strings.TrimSpace(webdav.Username)
|
||||
webdav.Password = strings.TrimSpace(webdav.Password)
|
||||
webdav.Timeout = util.NormalizeTimeout(webdav.Timeout)
|
||||
|
||||
Conf.Sync.WebDAV = webdav
|
||||
Conf.Save()
|
||||
|
|
|
|||
|
|
@ -161,6 +161,19 @@ func GetChildDocDepth(treeAbsPath string) (ret int) {
|
|||
return
|
||||
}
|
||||
|
||||
func NormalizeTimeout(timeout int) int {
|
||||
if 7 > timeout {
|
||||
if 1 > timeout {
|
||||
return 30
|
||||
}
|
||||
return 7
|
||||
}
|
||||
if 300 < timeout {
|
||||
return 300
|
||||
}
|
||||
return timeout
|
||||
}
|
||||
|
||||
func NormalizeEndpoint(endpoint string) string {
|
||||
endpoint = strings.TrimSpace(endpoint)
|
||||
if "" == endpoint {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue