mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-29 12:58:48 +01:00
🎨 Support local file system sync & backup (#13663)
* 🎨 Use local file system sync & backup * ⬆️ dejavu * 🎨 Add the settings panel of local file system sync & backup * 📝 Update user guides of local file system sync & backup * 🎨 Adjust supported runtime environments
This commit is contained in:
parent
0386bc9ebd
commit
6ee4705e2a
27 changed files with 408 additions and 32 deletions
|
|
@ -360,6 +360,13 @@ func InitConf() {
|
|||
Conf.Sync.WebDAV.Endpoint = util.NormalizeEndpoint(Conf.Sync.WebDAV.Endpoint)
|
||||
Conf.Sync.WebDAV.Timeout = util.NormalizeTimeout(Conf.Sync.WebDAV.Timeout)
|
||||
Conf.Sync.WebDAV.ConcurrentReqs = util.NormalizeConcurrentReqs(Conf.Sync.WebDAV.ConcurrentReqs, conf.ProviderWebDAV)
|
||||
if nil == Conf.Sync.Local {
|
||||
Conf.Sync.Local = &conf.Local{}
|
||||
}
|
||||
Conf.Sync.Local.Endpoint = util.NormalizeLocalPath(Conf.Sync.Local.Endpoint)
|
||||
Conf.Sync.Local.Timeout = util.NormalizeTimeout(Conf.Sync.Local.Timeout)
|
||||
Conf.Sync.Local.ConcurrentReqs = util.NormalizeConcurrentReqs(Conf.Sync.Local.ConcurrentReqs, conf.ProviderLocal)
|
||||
|
||||
if util.ContainerDocker == util.Container {
|
||||
Conf.Sync.Perception = false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -803,7 +803,7 @@ func DownloadCloudSnapshot(tag, id string) (err error) {
|
|||
util.PushErrMsg(Conf.Language(29), 5000)
|
||||
return
|
||||
}
|
||||
case conf.ProviderWebDAV, conf.ProviderS3:
|
||||
case conf.ProviderWebDAV, conf.ProviderS3, conf.ProviderLocal:
|
||||
if !IsPaidUser() {
|
||||
util.PushErrMsg(Conf.Language(214), 5000)
|
||||
return
|
||||
|
|
@ -845,7 +845,7 @@ func UploadCloudSnapshot(tag, id string) (err error) {
|
|||
util.PushErrMsg(Conf.Language(29), 5000)
|
||||
return
|
||||
}
|
||||
case conf.ProviderWebDAV, conf.ProviderS3:
|
||||
case conf.ProviderWebDAV, conf.ProviderS3, conf.ProviderLocal:
|
||||
if !IsPaidUser() {
|
||||
util.PushErrMsg(Conf.Language(214), 5000)
|
||||
return
|
||||
|
|
@ -891,7 +891,7 @@ func RemoveCloudRepoTag(tag string) (err error) {
|
|||
util.PushErrMsg(Conf.Language(29), 5000)
|
||||
return
|
||||
}
|
||||
case conf.ProviderWebDAV, conf.ProviderS3:
|
||||
case conf.ProviderWebDAV, conf.ProviderS3, conf.ProviderLocal:
|
||||
if !IsPaidUser() {
|
||||
util.PushErrMsg(Conf.Language(214), 5000)
|
||||
return
|
||||
|
|
@ -923,7 +923,7 @@ func GetCloudRepoTagSnapshots() (ret []*dejavu.Log, err error) {
|
|||
util.PushErrMsg(Conf.Language(29), 5000)
|
||||
return
|
||||
}
|
||||
case conf.ProviderWebDAV, conf.ProviderS3:
|
||||
case conf.ProviderWebDAV, conf.ProviderS3, conf.ProviderLocal:
|
||||
if !IsPaidUser() {
|
||||
util.PushErrMsg(Conf.Language(214), 5000)
|
||||
return
|
||||
|
|
@ -959,7 +959,7 @@ func GetCloudRepoSnapshots(page int) (ret []*dejavu.Log, pageCount, totalCount i
|
|||
util.PushErrMsg(Conf.Language(29), 5000)
|
||||
return
|
||||
}
|
||||
case conf.ProviderWebDAV, conf.ProviderS3:
|
||||
case conf.ProviderWebDAV, conf.ProviderS3, conf.ProviderLocal:
|
||||
if !IsPaidUser() {
|
||||
util.PushErrMsg(Conf.Language(214), 5000)
|
||||
return
|
||||
|
|
@ -1845,6 +1845,8 @@ func newRepository() (ret *dejavu.Repo, err error) {
|
|||
webdavClient.SetTimeout(time.Duration(cloudConf.WebDAV.Timeout) * time.Second)
|
||||
webdavClient.SetTransport(httpclient.NewTransport(cloudConf.WebDAV.SkipTlsVerify))
|
||||
cloudRepo = cloud.NewWebDAV(&cloud.BaseCloud{Conf: cloudConf}, webdavClient)
|
||||
case conf.ProviderLocal:
|
||||
cloudRepo = cloud.NewLocal(&cloud.BaseCloud{Conf: cloudConf})
|
||||
default:
|
||||
err = fmt.Errorf("unknown cloud provider [%d]", Conf.Sync.Provider)
|
||||
return
|
||||
|
|
@ -2129,6 +2131,12 @@ func buildCloudConf() (ret *cloud.Conf, err error) {
|
|||
Timeout: Conf.Sync.WebDAV.Timeout,
|
||||
ConcurrentReqs: Conf.Sync.WebDAV.ConcurrentReqs,
|
||||
}
|
||||
case conf.ProviderLocal:
|
||||
ret.Local = &cloud.ConfLocal{
|
||||
Endpoint: Conf.Sync.Local.Endpoint,
|
||||
Timeout: Conf.Sync.Local.Timeout,
|
||||
ConcurrentReqs: Conf.Sync.Local.ConcurrentReqs,
|
||||
}
|
||||
default:
|
||||
err = fmt.Errorf("invalid provider [%d]", Conf.Sync.Provider)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -252,7 +252,7 @@ func checkSync(boot, exit, byHand bool) bool {
|
|||
if !IsSubscriber() {
|
||||
return false
|
||||
}
|
||||
case conf.ProviderWebDAV, conf.ProviderS3:
|
||||
case conf.ProviderWebDAV, conf.ProviderS3, conf.ProviderLocal:
|
||||
if !IsPaidUser() {
|
||||
return false
|
||||
}
|
||||
|
|
@ -471,13 +471,28 @@ func SetSyncProviderWebDAV(webdav *conf.WebDAV) (err error) {
|
|||
return
|
||||
}
|
||||
|
||||
func SetSyncProviderLocal(local *conf.Local) (err error) {
|
||||
local.Endpoint = strings.TrimSpace(local.Endpoint)
|
||||
local.Endpoint = util.NormalizeLocalPath(local.Endpoint)
|
||||
|
||||
local.Timeout = util.NormalizeTimeout(local.Timeout)
|
||||
local.ConcurrentReqs = util.NormalizeConcurrentReqs(local.ConcurrentReqs, conf.ProviderLocal)
|
||||
|
||||
Conf.Sync.Local = local
|
||||
Conf.Save()
|
||||
return
|
||||
}
|
||||
|
||||
var (
|
||||
syncLock = sync.Mutex{}
|
||||
isSyncing = atomic.Bool{}
|
||||
)
|
||||
|
||||
func CreateCloudSyncDir(name string) (err error) {
|
||||
if conf.ProviderSiYuan != Conf.Sync.Provider {
|
||||
switch Conf.Sync.Provider {
|
||||
case conf.ProviderSiYuan, conf.ProviderLocal:
|
||||
break
|
||||
default:
|
||||
err = errors.New(Conf.Language(131))
|
||||
return
|
||||
}
|
||||
|
|
@ -502,7 +517,10 @@ func CreateCloudSyncDir(name string) (err error) {
|
|||
}
|
||||
|
||||
func RemoveCloudSyncDir(name string) (err error) {
|
||||
if conf.ProviderSiYuan != Conf.Sync.Provider {
|
||||
switch Conf.Sync.Provider {
|
||||
case conf.ProviderSiYuan, conf.ProviderLocal:
|
||||
break
|
||||
default:
|
||||
err = errors.New(Conf.Language(131))
|
||||
return
|
||||
}
|
||||
|
|
@ -678,6 +696,9 @@ func isProviderOnline(byHand bool) (ret bool) {
|
|||
checkURL = Conf.Sync.WebDAV.Endpoint
|
||||
skipTlsVerify = Conf.Sync.WebDAV.SkipTlsVerify
|
||||
timeout = Conf.Sync.WebDAV.Timeout * 1000
|
||||
case conf.ProviderLocal:
|
||||
checkURL = "file://" + Conf.Sync.Local.Endpoint
|
||||
timeout = Conf.Sync.Local.Timeout * 1000
|
||||
default:
|
||||
logging.LogWarnf("unknown provider: %d", Conf.Sync.Provider)
|
||||
return false
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue