🎨 S3/WebDAV 数据同步支持设置跳过 HTTPS 证书验证 Fix https://github.com/siyuan-note/siyuan/issues/6609

This commit is contained in:
Liang Ding 2022-11-16 19:39:15 +08:00
parent f9e670a3f6
commit ad3f7d8964
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
5 changed files with 55 additions and 15 deletions

View file

@ -77,6 +77,14 @@ const renderProvider = (provider: number) => {
<option ${window.siyuan.config.sync.s3.pathStyle ? "" : "selected"} value="false">Virtual-hosted-style</option>
<option ${window.siyuan.config.sync.s3.pathStyle ? "selected" : ""} value="true">Path-style</option>
</select>
</div>
<div class="b3-label b3-label--noborder">
<div>TLS verify</div>
<div class="fn__hr"></div>
<select class="b3-select fn__block" id="s3SkipTlsVerify">
<option ${window.siyuan.config.sync.s3.skipTlsVerify ? "" : "selected"} value="false">Verify</option>
<option ${window.siyuan.config.sync.s3.skipTlsVerify ? "selected" : ""} value="true">Skip</option>
</select>
</div>`;
}
return `${tip}
@ -112,6 +120,14 @@ const renderProvider = (provider: number) => {
<option ${window.siyuan.config.sync.s3.pathStyle ? "" : "selected"} value="false">Virtual-hosted-style</option>
<option ${window.siyuan.config.sync.s3.pathStyle ? "selected" : ""} value="true">Path-style</option>
</select>
</label>
<label class="b3-label b3-label--noborder fn__flex">
<div class="fn__flex-center fn__size200">TLS Verify</div>
<div class="fn__space"></div>
<select class="b3-select fn__flex-1" id="s3SkipTlsVerify">
<option ${window.siyuan.config.sync.s3.skipTlsVerify ? "" : "selected"} value="false">Verify</option>
<option ${window.siyuan.config.sync.s3.skipTlsVerify ? "selected" : ""} value="true">Skip</option>
</select>
</label>`;
} else if (provider === 3) {
const tip = `<div class="b3-label b3-label--inner">
@ -137,6 +153,14 @@ const renderProvider = (provider: number) => {
<div>Password</div>
<div class="fn__hr"></div>
<input id="password" class="b3-text-field fn__block" value="${window.siyuan.config.sync.webdav.password}">
</div>
<div class="b3-label b3-label--noborder">
<div>TLS verify</div>
<div class="fn__hr"></div>
<select class="b3-select fn__block" id="webdavSkipTlsVerify">
<option ${window.siyuan.config.sync.webdav.skipTlsVerify ? "" : "selected"} value="false">Verify</option>
<option ${window.siyuan.config.sync.webdav.skipTlsVerify ? "selected" : ""} value="true">Skip</option>
</select>
</div>`;
}
return `${tip}
@ -154,6 +178,14 @@ const renderProvider = (provider: number) => {
<div class="fn__flex-center fn__size200">Password</div>
<div class="fn__space"></div>
<input id="password" class="b3-text-field fn__flex-1" value="${window.siyuan.config.sync.webdav.password}">
</label>
<label class="b3-label b3-label--noborder fn__flex">
<div class="fn__flex-center fn__size200">TLS Verify</div>
<div class="fn__space"></div>
<select class="b3-select fn__flex-1" id="webdavSkipTlsVerify">
<option ${window.siyuan.config.sync.webdav.skipTlsVerify ? "" : "selected"} value="false">Verify</option>
<option ${window.siyuan.config.sync.webdav.skipTlsVerify ? "selected" : ""} value="true">Skip</option>
</select>
</label>`;
}
return "";
@ -222,6 +254,7 @@ const bindProviderEvent = () => {
bucket: (providerPanelElement.querySelector("#bucket") as HTMLInputElement).value,
pathStyle: (providerPanelElement.querySelector("#pathStyle") as HTMLInputElement).value === "true",
region: (providerPanelElement.querySelector("#region") as HTMLInputElement).value,
skipTlsVerify: (providerPanelElement.querySelector("#s3SkipTlsVerify") as HTMLInputElement).value === "true",
};
fetchPost("/api/sync/setSyncProviderS3", {s3}, () => {
window.siyuan.config.sync.s3 = s3;
@ -231,6 +264,7 @@ const bindProviderEvent = () => {
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",
};
fetchPost("/api/sync/setSyncProviderWebDAV", {webdav}, () => {
window.siyuan.config.sync.webdav = webdav;

View file

@ -340,11 +340,13 @@ declare interface IConfig {
secretKey: string
bucket: string
region: string
skipTlsVerify: boolean
}
webdav: {
endpoint: string
username: string
password: string
skipTlsVerify: boolean
}
},
lang: string

View file

@ -36,7 +36,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-20221116031102-5d5af638b8e5
github.com/siyuan-note/dejavu v0.0.0-20221116103627-5fbf73fe103e
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-20221007163134-7e64809023ef

View file

@ -359,8 +359,8 @@ 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-20221116031102-5d5af638b8e5 h1:m4+9OWYEKS832LJ9E1eAiUz0ATQAUo7gFs7E5S9JSho=
github.com/siyuan-note/dejavu v0.0.0-20221116031102-5d5af638b8e5/go.mod h1:PiWhnZhdVqhY0FifDg6kXwn75V97Dg3U/nFeD76fBis=
github.com/siyuan-note/dejavu v0.0.0-20221116103627-5fbf73fe103e h1:gwI3Zo+ce5GPZlau8kMcUipZwY1yJFjeG8ghwxB6YW4=
github.com/siyuan-note/dejavu v0.0.0-20221116103627-5fbf73fe103e/go.mod h1:PiWhnZhdVqhY0FifDg6kXwn75V97Dg3U/nFeD76fBis=
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=

View file

@ -828,7 +828,7 @@ func newRepository() (ret *dejavu.Repo, err error) {
s3HTTPClient.Timeout = 30 * time.Second
cloudRepo = cloud.NewS3(&cloud.BaseCloud{Conf: cloudConf}, s3HTTPClient)
case conf.ProviderWebDAV:
webdavClient := gowebdav.NewClient(cloudConf.Endpoint, cloudConf.WebDAV.Username, cloudConf.WebDAV.Password)
webdavClient := gowebdav.NewClient(cloudConf.WebDAV.Endpoint, cloudConf.WebDAV.Username, cloudConf.WebDAV.Password)
a := cloudConf.WebDAV.Username + ":" + cloudConf.WebDAV.Password
auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(a))
webdavClient.SetHeader("Authorization", auth)
@ -1049,18 +1049,22 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
case conf.ProviderSiYuan:
ret.Endpoint = "https://siyuan-data.b3logfile.com/"
case conf.ProviderS3:
ret.Endpoint = Conf.Sync.S3.Endpoint
ret.S3.AccessKey = Conf.Sync.S3.AccessKey
ret.S3.SecretKey = Conf.Sync.S3.SecretKey
ret.S3.Bucket = Conf.Sync.S3.Bucket
ret.S3.Region = Conf.Sync.S3.Region
ret.S3.PathStyle = Conf.Sync.S3.PathStyle
ret.S3.SkipTlsVerify = Conf.Sync.S3.SkipTlsVerify
ret.S3 = &cloud.ConfS3{
Endpoint: Conf.Sync.S3.Endpoint,
AccessKey: Conf.Sync.S3.AccessKey,
SecretKey: Conf.Sync.S3.SecretKey,
Bucket: Conf.Sync.S3.Bucket,
Region: Conf.Sync.S3.Region,
PathStyle: Conf.Sync.S3.PathStyle,
SkipTlsVerify: Conf.Sync.S3.SkipTlsVerify,
}
case conf.ProviderWebDAV:
ret.Endpoint = Conf.Sync.WebDAV.Endpoint
ret.WebDAV.Username = Conf.Sync.WebDAV.Username
ret.WebDAV.Password = Conf.Sync.WebDAV.Password
ret.WebDAV.SkipTlsVerify = Conf.Sync.WebDAV.SkipTlsVerify
ret.WebDAV = &cloud.ConfWebDAV{
Endpoint: Conf.Sync.WebDAV.Endpoint,
Username: Conf.Sync.WebDAV.Username,
Password: Conf.Sync.WebDAV.Password,
SkipTlsVerify: Conf.Sync.WebDAV.SkipTlsVerify,
}
default:
err = fmt.Errorf("invalid provider [%d]", Conf.Sync.Provider)
return