mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-09 00:34:20 +01:00
🎨 开源云端同步服务实现 https://github.com/siyuan-note/siyuan/issues/6445
This commit is contained in:
parent
be6380cbf7
commit
46cec73e2a
4 changed files with 7 additions and 28 deletions
|
|
@ -1009,7 +1009,7 @@ func subscribeEvents() {
|
|||
}
|
||||
|
||||
func buildCloudConf() (ret *cloud.Conf, err error) {
|
||||
if !IsValidCloudDirName(Conf.Sync.CloudName) {
|
||||
if !cloud.IsValidCloudDirName(Conf.Sync.CloudName) {
|
||||
logging.LogWarnf("invalid cloud repo name, rename it to [main]")
|
||||
Conf.Sync.CloudName = "main"
|
||||
Conf.Save()
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/dustin/go-humanize"
|
||||
|
|
@ -70,7 +69,7 @@ func BootSyncData() {
|
|||
util.IncBootProgress(3, "Syncing data from the cloud...")
|
||||
BootSyncSucc = 0
|
||||
|
||||
if !IsSubscriber() || !Conf.Sync.Enabled || "" == Conf.Sync.CloudName || !IsValidCloudDirName(Conf.Sync.CloudName) {
|
||||
if !IsSubscriber() || !Conf.Sync.Enabled || "" == Conf.Sync.CloudName || !cloud.IsValidCloudDirName(Conf.Sync.CloudName) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -135,7 +134,7 @@ func SyncData(boot, exit, byHand bool) {
|
|||
return
|
||||
}
|
||||
|
||||
if !IsValidCloudDirName(Conf.Sync.CloudName) {
|
||||
if !cloud.IsValidCloudDirName(Conf.Sync.CloudName) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -297,7 +296,7 @@ func CreateCloudSyncDir(name string) (err error) {
|
|||
|
||||
name = strings.TrimSpace(name)
|
||||
name = gulu.Str.RemoveInvisible(name)
|
||||
if !IsValidCloudDirName(name) {
|
||||
if !cloud.IsValidCloudDirName(name) {
|
||||
return errors.New(Conf.Language(37))
|
||||
}
|
||||
|
||||
|
|
@ -405,24 +404,6 @@ func formatErrorMsg(err error) string {
|
|||
return msg
|
||||
}
|
||||
|
||||
func IsValidCloudDirName(cloudDirName string) bool {
|
||||
if 16 < utf8.RuneCountInString(cloudDirName) || 1 > utf8.RuneCountInString(cloudDirName) {
|
||||
return false
|
||||
}
|
||||
|
||||
chars := []byte{'~', '`', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '+', '=',
|
||||
'[', ']', '{', '}', '\\', '|', ';', ':', '\'', '"', '<', ',', '>', '.', '?', '/', ' '}
|
||||
var charsStr string
|
||||
for _, char := range chars {
|
||||
charsStr += string(char)
|
||||
}
|
||||
|
||||
if strings.ContainsAny(cloudDirName, charsStr) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func getIgnoreLines() (ret []string) {
|
||||
ignore := filepath.Join(util.DataDir, ".siyuan", "syncignore")
|
||||
err := os.MkdirAll(filepath.Dir(ignore), 0755)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue