Skip to content

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

:bug: 导出较大的 PDF 预览白屏 https://github.com/siyuan-note/siyuan/issues/5875

Liang Ding70c520ac159e
diff --git a/kernel/api/export.go b/kernel/api/export.go
index 089136941b..68de07847d 100644
--- a/kernel/api/export.go
+++ b/kernel/api/export.go
@@ -18,7 +18,10 @@ package api
import (
"net/http"
+ "os"
"path"
+ "path/filepath"
+ "strings"
"github.com/88250/gulu"
"github.com/gin-gonic/gin"
@@ -190,11 +193,31 @@ func exportPreviewHTML(c *gin.Context) {
}
id := arg["id"].(string)
+ tpl := arg["tpl"].(string)
name, content := model.ExportHTML(id, "", true)
+ tpl = strings.ReplaceAll(tpl, "{tpl.name}", name)
+ tpl = strings.ReplaceAll(tpl, "{tpl.content}", content)
+ tmpName := gulu.Rand.String(7)
+ tmpDir := filepath.Join(util.TempDir, "export", "preview")
+ if err := os.MkdirAll(tmpDir, 0755); nil != err {
+ ret.Code = 1
+ ret.Msg = err.Error()
+ ret.Data = map[string]interface{}{"closeTimeout": 7000}
+ return
+ }
+ tmpPath := filepath.Join(tmpDir, tmpName)
+ if err := os.WriteFile(tmpPath, []byte(tpl), 0644); nil != err {
+ ret.Code = 1
+ ret.Msg = err.Error()
+ ret.Data = map[string]interface{}{"closeTimeout": 7000}
+ return
+ }
+
+ url := path.Join("http://127.0.0.1:6806", "export", "preview", tmpName)
ret.Data = map[string]interface{}{
- "id": id,
- "name": name,
- "content": content,
+ "id": id,
+ "name": name,
+ "url": url,
}
}