From d12b39c3c247698eff767800f5cd24bf86334a52 Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 15 Jun 2023 09:41:21 +0800 Subject: [PATCH 1/3] :art: Account title --- app/src/config/account.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/config/account.ts b/app/src/config/account.ts index 0fb4fa3af..2420c6901 100644 --- a/app/src/config/account.ts +++ b/app/src/config/account.ts @@ -398,7 +398,7 @@ ${window.siyuan.languages.account9} } if (window.siyuan.config.account.displayTitle && window.siyuan.user) { window.siyuan.user.userTitles.forEach(item => { - html += `
${item.icon}
`; + html += `
${item.icon}
`; }); } document.getElementById("toolbarVIP").innerHTML = html; From e93c62e49f4edcc2533bd631735b9c7127caf12c Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 15 Jun 2023 09:41:42 +0800 Subject: [PATCH 2/3] :art: Improve file copy --- kernel/go.mod | 6 +++--- kernel/go.sum | 6 ++++++ kernel/model/export.go | 4 ++-- kernel/model/import.go | 4 ++-- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/kernel/go.mod b/kernel/go.mod index c4cbc0ff9..59c51a23b 100644 --- a/kernel/go.mod +++ b/kernel/go.mod @@ -48,7 +48,7 @@ require ( github.com/siyuan-note/dejavu v0.0.0-20230612120039-bba808ca7649 github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b - github.com/siyuan-note/filelock v0.0.0-20230523004741-d9121740f638 + github.com/siyuan-note/filelock v0.0.0-20230615011542-df9ae6b3f981 github.com/siyuan-note/httpclient v0.0.0-20230610031552-11458e2e39b0 github.com/siyuan-note/logging v0.0.0-20230327073243-ebe83aec1493 github.com/siyuan-note/riff v0.0.0-20230516073320-b440b8feaabd @@ -59,7 +59,7 @@ require ( golang.org/x/image v0.7.0 golang.org/x/mobile v0.0.0-20230531173138-3c911d8e3eda golang.org/x/mod v0.10.0 - golang.org/x/text v0.9.0 + golang.org/x/text v0.10.0 ) require ( @@ -132,7 +132,7 @@ require ( golang.org/x/exp v0.0.0-20230522175609-2e198f4a06a1 // indirect golang.org/x/net v0.10.0 // indirect golang.org/x/sync v0.2.0 // indirect - golang.org/x/sys v0.8.0 // indirect + golang.org/x/sys v0.9.0 // indirect golang.org/x/tools v0.9.3 // indirect google.golang.org/protobuf v1.30.0 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect diff --git a/kernel/go.sum b/kernel/go.sum index 5faa32d0f..52993d615 100644 --- a/kernel/go.sum +++ b/kernel/go.sum @@ -289,6 +289,8 @@ github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b h1:828lTUW2C0 github.com/siyuan-note/eventbus v0.0.0-20230216103454-41885eac6c2b/go.mod h1:Sqo4FYX5lAXu7gWkbEdJF0e6P57tNNVV4WDKYDctokI= github.com/siyuan-note/filelock v0.0.0-20230523004741-d9121740f638 h1:0dvT+1FvuUf6/GFkFRQML0Q3DLulbswj1GJJ0j7BlD8= github.com/siyuan-note/filelock v0.0.0-20230523004741-d9121740f638/go.mod h1:v2bpUtjvsvt1TRHgly1mIXQjAEo/t50dOM9YiC813qQ= +github.com/siyuan-note/filelock v0.0.0-20230615011542-df9ae6b3f981 h1:ulmzDD3Z3tsJAIec9sLLGuK88tuuE2o9Ux8Vog8KQBc= +github.com/siyuan-note/filelock v0.0.0-20230615011542-df9ae6b3f981/go.mod h1:jK5lCYfPbFOrW23/HMeU7kmpLdEd5GkennF+kUpy7Vs= github.com/siyuan-note/httpclient v0.0.0-20230610031552-11458e2e39b0 h1:RKdpy6P1LjUBgQ/7hKO+UmcSwfWzcpMAKRh/deNiVXQ= github.com/siyuan-note/httpclient v0.0.0-20230610031552-11458e2e39b0/go.mod h1:wqRaWZoA/NZJzZ6aCszp75Bi6dH7ZVcb8JWRysvrC2Y= github.com/siyuan-note/logging v0.0.0-20230327073243-ebe83aec1493 h1:oaN5b0WDFkjdBgGxmmBnMrtZxaJ76LZLwhQSZnznJMI= @@ -411,6 +413,8 @@ golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.8.0 h1:EBmGv8NaZBZTWvrbjNoL6HVt+IVy3QDQpJs7VRIw3tU= golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.9.0 h1:KS/R3tvhPqvJvwcKfnBHJwwthS11LRhmM5D59eEXa0s= +golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -428,6 +432,8 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= golang.org/x/text v0.9.0 h1:2sjJmO8cDvYveuX97RDLsxlyUxLl+GHoLxBiRdHllBE= golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.10.0 h1:UpjohKhiEgNc0CSauXmwYftY1+LlaC75SJwh0SgCX58= +golang.org/x/text v0.10.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= diff --git a/kernel/model/export.go b/kernel/model/export.go index 89300b354..fde5e01fe 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -257,7 +257,7 @@ func ExportDataInFolder(exportFolder string) (name string, err error) { name = filepath.Base(zipPath) targetZipPath := filepath.Join(exportFolder, name) zipAbsPath := filepath.Join(util.TempDir, "export", name) - err = filelock.RoboCopy(zipAbsPath, targetZipPath) + err = filelock.Copy(zipAbsPath, targetZipPath) if nil != err { logging.LogErrorf("copy export zip from [%s] to [%s] failed: %s", zipAbsPath, targetZipPath, err) return @@ -291,7 +291,7 @@ func exportData(exportFolder string) (zipPath string, err error) { } data := filepath.Join(util.WorkspaceDir, "data") - if err = filelock.RoboCopy(data, exportFolder); nil != err { + if err = filelock.Copy(data, exportFolder); nil != err { logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", data, baseFolderName, err) err = errors.New(fmt.Sprintf(Conf.Language(14), err.Error())) return diff --git a/kernel/model/import.go b/kernel/model/import.go index acc8e0a88..410ed9896 100644 --- a/kernel/model/import.go +++ b/kernel/model/import.go @@ -383,7 +383,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) { return nil }) - if err = filelock.RoboCopy(unzipRootPath, targetDir); nil != err { + if err = filelock.Copy(unzipRootPath, targetDir); nil != err { logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", unzipRootPath, util.DataDir, err) err = errors.New("copy data failed") return @@ -440,7 +440,7 @@ func ImportData(zipPath string) (err error) { } tmpDataPath := filepath.Join(unzipPath, dirs[0].Name()) - if err = filelock.RoboCopy(tmpDataPath, util.DataDir); nil != err { + if err = filelock.Copy(tmpDataPath, util.DataDir); nil != err { logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", tmpDataPath, util.DataDir, err) err = errors.New("copy data failed") return From a515a4f992a66a9ae77fda9ba3aca4e7e3387b8e Mon Sep 17 00:00:00 2001 From: Daniel <845765@qq.com> Date: Thu, 15 Jun 2023 10:15:13 +0800 Subject: [PATCH 3/3] :bug: Pandoc is not initialized in some cases Fix https://github.com/siyuan-note/siyuan/issues/8533 --- kernel/api/export.go | 2 +- kernel/model/conf.go | 15 ++++++++++++++- kernel/model/export.go | 6 +++++- kernel/model/index.go | 4 ++++ kernel/model/repository.go | 4 ++-- kernel/util/pandoc.go | 3 +++ kernel/util/runtime.go | 4 ++++ 7 files changed, 33 insertions(+), 5 deletions(-) diff --git a/kernel/api/export.go b/kernel/api/export.go index 458310ac8..503c86518 100644 --- a/kernel/api/export.go +++ b/kernel/api/export.go @@ -347,7 +347,7 @@ func exportDocx(c *gin.Context) { } err := model.ExportDocx(id, savePath, removeAssets, merge) if nil != err { - ret.Code = 1 + ret.Code = -1 ret.Msg = err.Error() ret.Data = map[string]interface{}{"closeTimeout": 7000} return diff --git a/kernel/model/conf.go b/kernel/model/conf.go index 6ba7b505c..2de6e212d 100644 --- a/kernel/model/conf.go +++ b/kernel/model/conf.go @@ -19,7 +19,6 @@ package model import ( "bytes" "fmt" - "github.com/sashabaranov/go-openai" "os" "path/filepath" "runtime" @@ -35,6 +34,8 @@ import ( "github.com/Xuanwo/go-locale" "github.com/dustin/go-humanize" "github.com/getsentry/sentry-go" + "github.com/sashabaranov/go-openai" + "github.com/siyuan-note/eventbus" "github.com/siyuan-note/filelock" "github.com/siyuan-note/logging" "github.com/siyuan-note/siyuan/kernel/conf" @@ -892,3 +893,15 @@ func upgradeUserGuide() { index(boxID) } } + +func init() { + subscribeConfEvents() +} + +func subscribeConfEvents() { + eventbus.Subscribe(util.EvtConfPandocInitialized, func() { + logging.LogInfof("pandoc initialized, set pandoc bin to [%s]", util.PandocBinPath) + Conf.Export.PandocBin = util.PandocBinPath + Conf.Save() + }) +} diff --git a/kernel/model/export.go b/kernel/model/export.go index fde5e01fe..8f66d3d53 100644 --- a/kernel/model/export.go +++ b/kernel/model/export.go @@ -333,7 +333,11 @@ func Preview(id string) string { func ExportDocx(id, savePath string, removeAssets, merge bool) (err error) { if !util.IsValidPandocBin(Conf.Export.PandocBin) { - return errors.New(Conf.Language(115)) + Conf.Export.PandocBin = util.PandocBinPath + Conf.Save() + if !util.IsValidPandocBin(Conf.Export.PandocBin) { + return errors.New(Conf.Language(115)) + } } tmpDir := filepath.Join(util.TempDir, "export", gulu.Rand.String(7)) diff --git a/kernel/model/index.go b/kernel/model/index.go index 39828c455..a05271116 100644 --- a/kernel/model/index.go +++ b/kernel/model/index.go @@ -253,6 +253,10 @@ func updateEmbedBlockContent(embedBlockID string, queryResultBlocks []*EmbedBloc } func init() { + subscribeSQLEvents() +} + +func subscribeSQLEvents() { //eventbus.Subscribe(eventbus.EvtSQLInsertBlocks, func(context map[string]interface{}, current, total, blockCount int, hash string) { // if util.ContainerAndroid == util.Container || util.ContainerIOS == util.Container { // // Android/iOS 端不显示数据索引和搜索索引状态提示 https://github.com/siyuan-note/siyuan/issues/6392 diff --git a/kernel/model/repository.go b/kernel/model/repository.go index 7c53af141..703c34d38 100644 --- a/kernel/model/repository.go +++ b/kernel/model/repository.go @@ -57,7 +57,7 @@ import ( ) func init() { - subscribeEvents() + subscribeRepoEvents() } type Snapshot struct { @@ -1476,7 +1476,7 @@ func newRepository() (ret *dejavu.Repo, err error) { return } -func subscribeEvents() { +func subscribeRepoEvents() { eventbus.Subscribe(eventbus.EvtIndexBeforeWalkData, func(context map[string]interface{}, path string) { msg := fmt.Sprintf(Conf.Language(158), path) util.SetBootDetails(msg) diff --git a/kernel/util/pandoc.go b/kernel/util/pandoc.go index 96cf43326..ca8f3279e 100644 --- a/kernel/util/pandoc.go +++ b/kernel/util/pandoc.go @@ -25,6 +25,7 @@ import ( "strings" "github.com/88250/gulu" + "github.com/siyuan-note/eventbus" "github.com/siyuan-note/logging" ) @@ -105,6 +106,8 @@ func initPandoc() { } } + defer eventbus.Publish(EvtConfPandocInitialized) + if gulu.OS.IsWindows() { PandocBinPath = filepath.Join(pandocDir, "bin", "pandoc.exe") } else if gulu.OS.IsDarwin() || gulu.OS.IsLinux() { diff --git a/kernel/util/runtime.go b/kernel/util/runtime.go index 65d460c0f..dbf223513 100644 --- a/kernel/util/runtime.go +++ b/kernel/util/runtime.go @@ -401,3 +401,7 @@ func existAvailabilityStatus(workspaceAbsPath string) bool { } return false } + +const ( + EvtConfPandocInitialized = "conf.pandoc.initialized" +)