🎨 数据同步接入 S3 协议兼容的对象存储服务 Fix https://github.com/siyuan-note/siyuan/issues/6528

This commit is contained in:
Liang Ding 2022-11-09 17:50:08 +08:00
parent 9e544ed154
commit 41d9a317dc
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
5 changed files with 3 additions and 49 deletions

View file

@ -24,10 +24,8 @@ type Sync struct {
Stat string `json:"stat"` // 最近同步统计信息
GenerateConflictDoc bool `json:"generateConflictDoc"` // 云端同步冲突时是否生成冲突文档
Provider int `json:"provider"` // 云端存储服务提供者
Qiniu *Qiniu `json:"qiniu"` // 七牛云存储服务配置
S3 *S3 `json:"s3"` // S3 对象存储服务配置
WebDAV *WebDAV `json:"webdav"` // WebDAV 服务配置
OSS *OSS `json:"oss"` // 阿里云 OSS 存储服务配置
}
func NewSync() *Sync {
@ -40,20 +38,6 @@ func NewSync() *Sync {
}
}
type Qiniu struct {
Endpoint string `json:"endpoint"` // 服务端点
AccessKey string `json:"accessKey"` // Access Key
SecretKey string `json:"secretKey"` // Secret Key
Bucket string `json:"bucket"` // 存储空间
}
type OSS struct {
Endpoint string `json:"endpoint"` // 服务端点
AccessKey string `json:"accessKey"` // Access Key
SecretKey string `json:"secretKey"` // Secret Key
Bucket string `json:"bucket"` // 存储空间
}
type S3 struct {
Endpoint string `json:"endpoint"` // 服务端点
AccessKey string `json:"accessKey"` // Access Key
@ -70,8 +54,6 @@ type WebDAV struct {
const (
ProviderSiYuan = 0 // ProviderSiYuan 为思源官方提供的云端存储服务
ProviderQiniu = 1 // ProviderQiniu 为七牛云提供的云端存储服务
ProviderS3 = 2 // ProviderS3 为 S3 协议对象存储提供的云端存储服务
ProviderWebDAV = 3 // ProviderWebDAV 为 WebDAV 协议提供的云端存储服务
ProviderOSS = 4 // ProviderOSS 为阿里云 OSS 存储服务提供的云端存储服务
)

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-20221109070851-d7221921a76d
github.com/siyuan-note/dejavu v0.0.0-20221109094611-dfa0c92ec2f9
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
@ -56,7 +56,6 @@ require (
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver/v3 v3.1.1 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef // indirect
github.com/aws/aws-sdk-go v1.44.133 // indirect
@ -120,7 +119,6 @@ require (
golang.org/x/net v0.2.0 // indirect
golang.org/x/sync v0.1.0 // indirect
golang.org/x/sys v0.2.0 // indirect
golang.org/x/time v0.2.0 // indirect
golang.org/x/tools v0.2.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect

View file

@ -39,8 +39,6 @@ github.com/Xuanwo/go-locale v1.1.0 h1:51gUxhxl66oXAjI9uPGb2O0qwPECpriKQb2hl35mQk
github.com/Xuanwo/go-locale v1.1.0/go.mod h1:UKrHoZB3FPIk9wIG2/tVSobnHgNnceGSH3Y8DY5cASs=
github.com/alecthomas/chroma v0.10.0 h1:7XDcGkCQopCNKjZHfYrNLraA+M7e0fMiJ/Mfikbfjek=
github.com/alecthomas/chroma v0.10.0/go.mod h1:jtJATyUxlIORhUOFNA9NZDWGAQ8wpxQQqNSB4rjA/1s=
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible h1:QoRMR0TCctLDqBCMyOu1eXdZyMw3F7uGA9qPn2J4+R8=
github.com/aliyun/aliyun-oss-go-sdk v2.2.5+incompatible/go.mod h1:T/Aws4fEfogEE9v+HPhhw+CntffsBHJ8nXQCwKr0/g8=
github.com/andybalholm/cascadia v1.3.1 h1:nhxRkql1kdYCc8Snf7D5/D3spOX+dBgjA6u8x004T2c=
github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA=
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
@ -361,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-20221109070851-d7221921a76d h1:OSj2Cbd1gu85rSJerjMzMMX35ra5Jbq9o8sBXKpFUaI=
github.com/siyuan-note/dejavu v0.0.0-20221109070851-d7221921a76d/go.mod h1:ag2Wgs0tQlW+5kqQijK16cyoYXw2lgiphFbHsV6XnhY=
github.com/siyuan-note/dejavu v0.0.0-20221109094611-dfa0c92ec2f9 h1:4YGkiQDWrFwDM4dG7JRr7RXO9b4/92enlFw/CsrwxAI=
github.com/siyuan-note/dejavu v0.0.0-20221109094611-dfa0c92ec2f9/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=
@ -551,8 +549,6 @@ golang.org/x/text v0.4.0 h1:BrVqGRd7+k1DiOgtnFvAkoQEWQvBc25ouMJM6429SFg=
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/time v0.2.0 h1:52I/1L54xyEQAYdtcSuxtiT84KGYTBGXwayxmIpNJhE=
golang.org/x/time v0.2.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20181030000716-a0a13e073c7b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=

View file

@ -242,10 +242,6 @@ func InitConf() {
if 0 == Conf.Sync.Mode {
Conf.Sync.Mode = 1
}
if nil == Conf.Sync.Qiniu {
Conf.Sync.Qiniu = &conf.Qiniu{}
}
Conf.Sync.Qiniu.Endpoint = util.NormalizeEndpoint(Conf.Sync.Qiniu.Endpoint)
if nil == Conf.Sync.S3 {
Conf.Sync.S3 = &conf.S3{}
}
@ -254,10 +250,6 @@ func InitConf() {
Conf.Sync.WebDAV = &conf.WebDAV{}
}
Conf.Sync.WebDAV.Endpoint = util.NormalizeEndpoint(Conf.Sync.WebDAV.Endpoint)
if nil == Conf.Sync.OSS {
Conf.Sync.OSS = &conf.OSS{}
}
Conf.Sync.OSS.Endpoint = util.NormalizeEndpoint(Conf.Sync.OSS.Endpoint)
if nil == Conf.Api {
Conf.Api = conf.NewAPI()

View file

@ -821,8 +821,6 @@ func newRepository() (ret *dejavu.Repo, err error) {
switch Conf.Sync.Provider {
case conf.ProviderSiYuan:
cloudRepo = cloud.NewSiYuan(&cloud.BaseCloud{Conf: cloudConf})
case conf.ProviderQiniu:
cloudRepo = cloud.NewQiniu(&cloud.BaseCloud{Conf: cloudConf})
case conf.ProviderS3:
cloudRepo = cloud.NewS3(&cloud.BaseCloud{Conf: cloudConf})
case conf.ProviderWebDAV:
@ -833,8 +831,6 @@ func newRepository() (ret *dejavu.Repo, err error) {
webdavClient.SetHeader("User-Agent", util.UserAgent)
webdavClient.SetTimeout(30 * time.Second)
cloudRepo = cloud.NewWebDAV(&cloud.BaseCloud{Conf: cloudConf}, webdavClient)
case conf.ProviderOSS:
cloudRepo = cloud.NewOSS(&cloud.BaseCloud{Conf: cloudConf})
default:
err = fmt.Errorf("unknown cloud provider [%d]", Conf.Sync.Provider)
return
@ -1047,11 +1043,6 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
switch Conf.Sync.Provider {
case conf.ProviderSiYuan:
ret.Endpoint = "https://siyuan-data.b3logfile.com/"
case conf.ProviderQiniu:
ret.Endpoint = Conf.Sync.Qiniu.Endpoint
ret.AccessKey = Conf.Sync.Qiniu.AccessKey
ret.SecretKey = Conf.Sync.Qiniu.SecretKey
ret.Bucket = Conf.Sync.Qiniu.Bucket
case conf.ProviderS3:
ret.Endpoint = Conf.Sync.S3.Endpoint
ret.AccessKey = Conf.Sync.S3.AccessKey
@ -1062,11 +1053,6 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
ret.Endpoint = Conf.Sync.WebDAV.Endpoint
ret.Username = Conf.Sync.WebDAV.Username
ret.Password = Conf.Sync.WebDAV.Password
case conf.ProviderOSS:
ret.Endpoint = Conf.Sync.OSS.Endpoint
ret.AccessKey = Conf.Sync.OSS.AccessKey
ret.SecretKey = Conf.Sync.OSS.SecretKey
ret.Bucket = Conf.Sync.OSS.Bucket
default:
err = fmt.Errorf("invalid provider [%d]", Conf.Sync.Provider)
return