Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:bug: Pandoc is not initialized in some cases Fix https://github.com/siyuan-note/siyuan/issues/8533

Daniela515a4f992a6
diff --git a/kernel/api/export.go b/kernel/api/export.go
index 458310ac8a..503c865188 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 6ba7b505c9..2de6e212d8 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 fde5e01feb..8f66d3d53a 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 39828c4559..a052711163 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 7c53af1418..703c34d38e 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 96cf43326e..ca8f3279e0 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 65d460c0ff..dbf2235132 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"
+)