diff --git a/app/src/config/repos.ts b/app/src/config/repos.ts
index a6db061eb..209ccd3fa 100644
--- a/app/src/config/repos.ts
+++ b/app/src/config/repos.ts
@@ -85,7 +85,13 @@ const renderProvider = (provider: number) => {
-`;
+
+
+`;
}
return `${tip}
+`;
} else if (provider === 3) {
const tip = `
@@ -161,6 +172,11 @@ const renderProvider = (provider: number) => {
+
+`;
}
return `${tip}
@@ -186,6 +202,11 @@ const renderProvider = (provider: number) => {
+
+`;
}
return "";
@@ -247,6 +268,18 @@ const bindProviderEvent = () => {
providerPanelElement.querySelectorAll(".b3-text-field, .b3-select").forEach(item => {
item.addEventListener("blur", () => {
if (window.siyuan.config.sync.provider === 2) {
+ let timeout = parseInt((providerPanelElement.querySelector("#timeout") as HTMLInputElement).value, 10);
+ if (7 > timeout) {
+ if (1 > timeout) {
+ timeout = 30
+ } else {
+ timeout = 7;
+ }
+ }
+ if (300 < timeout) {
+ timeout = 300;
+ }
+ (providerPanelElement.querySelector("#timeout") as HTMLInputElement).value = timeout.toString();
const s3 = {
endpoint: (providerPanelElement.querySelector("#endpoint") as HTMLInputElement).value,
accessKey: (providerPanelElement.querySelector("#accessKey") as HTMLInputElement).value,
@@ -255,16 +288,26 @@ const bindProviderEvent = () => {
pathStyle: (providerPanelElement.querySelector("#pathStyle") as HTMLInputElement).value === "true",
region: (providerPanelElement.querySelector("#region") as HTMLInputElement).value,
skipTlsVerify: (providerPanelElement.querySelector("#s3SkipTlsVerify") as HTMLInputElement).value === "true",
+ timeout: timeout,
};
fetchPost("/api/sync/setSyncProviderS3", {s3}, () => {
window.siyuan.config.sync.s3 = s3;
});
} else if (window.siyuan.config.sync.provider === 3) {
+ let timeout = parseInt((providerPanelElement.querySelector("#timeout") as HTMLInputElement).value, 10)
+ if (7 > timeout) {
+ timeout = 7;
+ }
+ if (300 < timeout) {
+ timeout = 300;
+ }
+ (providerPanelElement.querySelector("#timeout") as HTMLInputElement).value = timeout.toString();
const webdav = {
endpoint: (providerPanelElement.querySelector("#endpoint") as HTMLInputElement).value,
username: (providerPanelElement.querySelector("#username") as HTMLInputElement).value,
password: (providerPanelElement.querySelector("#password") as HTMLInputElement).value,
skipTlsVerify: (providerPanelElement.querySelector("#webdavSkipTlsVerify") as HTMLInputElement).value === "true",
+ timeout: timeout,
};
fetchPost("/api/sync/setSyncProviderWebDAV", {webdav}, () => {
window.siyuan.config.sync.webdav = webdav;
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index a5e490c1e..a788c501d 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -372,12 +372,14 @@ declare interface IConfig {
bucket: string
region: string
skipTlsVerify: boolean
+ timeout: number
}
webdav: {
endpoint: string
username: string
password: string
skipTlsVerify: boolean
+ timeout: number
}
},
lang: string
diff --git a/kernel/conf/sync.go b/kernel/conf/sync.go
index 752c18f4c..f21bb6c66 100644
--- a/kernel/conf/sync.go
+++ b/kernel/conf/sync.go
@@ -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 (
diff --git a/kernel/go.mod b/kernel/go.mod
index 19dfdfe60..26e6bc595 100644
--- a/kernel/go.mod
+++ b/kernel/go.mod
@@ -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
diff --git a/kernel/go.sum b/kernel/go.sum
index f14744bae..43642c6f2 100644
--- a/kernel/go.sum
+++ b/kernel/go.sum
@@ -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=
diff --git a/kernel/model/conf.go b/kernel/model/conf.go
index ce42efa38..6a670fb4b 100644
--- a/kernel/model/conf.go
+++ b/kernel/model/conf.go
@@ -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()
diff --git a/kernel/model/repository.go b/kernel/model/repository.go
index 00a07e35b..af0134a56 100644
--- a/kernel/model/repository.go
+++ b/kernel/model/repository.go
@@ -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)
diff --git a/kernel/model/sync.go b/kernel/model/sync.go
index e8e3a1a1c..67fd8e43d 100644
--- a/kernel/model/sync.go
+++ b/kernel/model/sync.go
@@ -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()
diff --git a/kernel/util/path.go b/kernel/util/path.go
index a9cc81a79..be1953b6a 100644
--- a/kernel/util/path.go
+++ b/kernel/util/path.go
@@ -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 {