mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-07 08:01:47 +01:00
🎨 Support setting automatic sync interval https://github.com/siyuan-note/siyuan/issues/13448
This commit is contained in:
parent
152fa6e6e0
commit
45a6f7e29d
18 changed files with 100 additions and 12 deletions
|
|
@ -237,6 +237,7 @@ func ServeAPI(ginServer *gin.Engine) {
|
|||
ginServer.Handle("POST", "/api/cloud/getCloudSpace", model.CheckAuth, model.CheckAdminRole, getCloudSpace)
|
||||
|
||||
ginServer.Handle("POST", "/api/sync/setSyncEnable", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSyncEnable)
|
||||
ginServer.Handle("POST", "/api/sync/setSyncInterval", model.CheckAuth, setSyncInterval)
|
||||
ginServer.Handle("POST", "/api/sync/setSyncPerception", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSyncPerception)
|
||||
ginServer.Handle("POST", "/api/sync/setSyncGenerateConflictDoc", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSyncGenerateConflictDoc)
|
||||
ginServer.Handle("POST", "/api/sync/setSyncMode", model.CheckAuth, model.CheckAdminRole, model.CheckReadonly, setSyncMode)
|
||||
|
|
|
|||
|
|
@ -541,6 +541,17 @@ func setSyncEnable(c *gin.Context) {
|
|||
model.SetSyncEnable(enabled)
|
||||
}
|
||||
|
||||
func setSyncInterval(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
arg, ok := util.JsonArg(c, ret)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
interval := int(arg["interval"].(float64))
|
||||
model.SetSyncInterval(interval)
|
||||
}
|
||||
|
||||
func setSyncPerception(c *gin.Context) {
|
||||
ret := gulu.Ret.NewResult()
|
||||
defer c.JSON(http.StatusOK, ret)
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ type Sync struct {
|
|||
Enabled bool `json:"enabled"` // 是否开启同步
|
||||
Perception bool `json:"perception"` // 是否开启感知
|
||||
Mode int `json:"mode"` // 同步模式,0:未设置(为兼容已有配置,initConf 函数中会转换为 1),1:自动,2:手动 https://github.com/siyuan-note/siyuan/issues/5089,3:完全手动 https://github.com/siyuan-note/siyuan/issues/7295
|
||||
Interval int `json:"interval"` // 自动同步间隔,单位:秒
|
||||
Synced int64 `json:"synced"` // 最近同步时间
|
||||
Stat string `json:"stat"` // 最近同步统计信息
|
||||
GenerateConflictDoc bool `json:"generateConflictDoc"` // 云端同步冲突时是否生成冲突文档
|
||||
|
|
@ -37,6 +38,7 @@ func NewSync() *Sync {
|
|||
Mode: 1,
|
||||
GenerateConflictDoc: false,
|
||||
Provider: ProviderSiYuan,
|
||||
Interval: 30,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -344,6 +344,12 @@ func InitConf() {
|
|||
if 0 == Conf.Sync.Mode {
|
||||
Conf.Sync.Mode = 1
|
||||
}
|
||||
if 30 > Conf.Sync.Interval {
|
||||
Conf.Sync.Interval = 30
|
||||
}
|
||||
if 60*60*12 < Conf.Sync.Interval {
|
||||
Conf.Sync.Interval = 60 * 60 * 12
|
||||
}
|
||||
if nil == Conf.Sync.S3 {
|
||||
Conf.Sync.S3 = &conf.S3{PathStyle: true, SkipTlsVerify: true}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -389,6 +389,20 @@ func SetSyncEnable(b bool) {
|
|||
return
|
||||
}
|
||||
|
||||
func SetSyncInterval(interval int) {
|
||||
if 30 > interval {
|
||||
interval = 30
|
||||
}
|
||||
if 43200 < interval {
|
||||
interval = 43200
|
||||
}
|
||||
|
||||
Conf.Sync.Interval = interval
|
||||
Conf.Save()
|
||||
planSyncAfter(time.Duration(interval) * time.Second)
|
||||
return
|
||||
}
|
||||
|
||||
func SetSyncPerception(b bool) {
|
||||
if util.ContainerDocker == util.Container {
|
||||
b = false
|
||||
|
|
@ -641,7 +655,7 @@ func getSyncIgnoreLines() (ret []string) {
|
|||
|
||||
func IncSync() {
|
||||
syncSameCount.Store(0)
|
||||
planSyncAfter(30 * time.Second)
|
||||
planSyncAfter(time.Duration(Conf.Sync.Interval) * time.Second)
|
||||
}
|
||||
|
||||
func planSyncAfter(d time.Duration) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue