From 70c520ac159ecb924749ee22cbe43e3ee823b421 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Sat, 17 Sep 2022 09:26:08 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E5=AF=BC=E5=87=BA=E8=BE=83=E5=A4=A7?= =?UTF-8?q?=E7=9A=84=20PDF=20=E9=A2=84=E8=A7=88=E7=99=BD=E5=B1=8F=20https:?= =?UTF-8?q?//github.com/siyuan-note/siyuan/issues/5875?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kernel/api/export.go | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/kernel/api/export.go b/kernel/api/export.go index 089136941..68de07847 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, } }