From 1809c27f60a78e5e34c01e5e41ae28ffdf244ed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A2=96=E9=80=B8?= <49649786+Zuoqiu-Yingyi@users.noreply.github.com> Date: Fri, 28 Oct 2022 08:29:41 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=8E=A8=20=E6=94=B9=E8=BF=9B=E4=BC=BA?= =?UTF-8?q?=E6=9C=8D=E4=BB=A3=E7=A0=81=E7=89=87=E6=AE=B5=20`/snippets/`=20?= =?UTF-8?q?#6356=20(#6380)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * :bug: fix #5857 * :art: #5990 桌面端 `SiYuan` 可执行程序支持使用参数连接非本机内核服务 * :art: style * :art: style * :art: style * 🎨 改进伺服代码片段 `/snippets/` #6356 --- kernel/api/snippet.go | 11 ++++++----- kernel/util/working.go | 2 ++ kernel/util/working_mobile.go | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/kernel/api/snippet.go b/kernel/api/snippet.go index 5f186f1b2..2b7402fad 100644 --- a/kernel/api/snippet.go +++ b/kernel/api/snippet.go @@ -32,16 +32,16 @@ import ( ) func serveSnippets(c *gin.Context) { - name := strings.TrimPrefix(c.Request.URL.Path, "/snippets/") - ext := filepath.Ext(name) - name = strings.TrimSuffix(name, ext) + filePath := strings.TrimPrefix(c.Request.URL.Path, "/snippets/") + ext := filepath.Ext(filePath) + name := strings.TrimSuffix(filePath, ext) confSnippets, err := model.LoadSnippets() if nil != err { logging.LogErrorf("load snippets failed: %s", name, err) c.Status(404) return } - + for _, s := range confSnippets { if s.Name == name && ("" != ext && s.Type == ext[1:]) { c.Header("Content-Type", mime.TypeByExtension(ext)) @@ -49,7 +49,8 @@ func serveSnippets(c *gin.Context) { return } } - c.Status(404) + filePath = filepath.Join(util.SnippetsPath, filePath) + c.File(filePath) } func getSnippet(c *gin.Context) { diff --git a/kernel/util/working.go b/kernel/util/working.go index 2cdd3120c..623597dca 100644 --- a/kernel/util/working.go +++ b/kernel/util/working.go @@ -172,6 +172,7 @@ var ( AppearancePath string // 配置目录下的外观目录 appearance/ 路径 ThemesPath string // 配置目录下的外观目录下的 themes/ 路径 IconsPath string // 配置目录下的外观目录下的 icons/ 路径 + SnippetsPath string // 数据目录下的 snippets/ 路径 AndroidNativeLibDir string // Android 库路径 AndroidPrivateDataDir string // Android 私有数据路径 @@ -274,6 +275,7 @@ func initWorkspaceDir(workspaceArg string) { DBPath = filepath.Join(TempDir, DBName) HistoryDBPath = filepath.Join(TempDir, "history.db") BlockTreePath = filepath.Join(TempDir, "blocktree.msgpack") + SnippetsPath = filepath.Join(DataDir, "snippets") } var ( diff --git a/kernel/util/working_mobile.go b/kernel/util/working_mobile.go index 0f98a2dc4..377f1ae8f 100644 --- a/kernel/util/working_mobile.go +++ b/kernel/util/working_mobile.go @@ -60,6 +60,7 @@ func BootMobile(container, appDir, workspaceDir, nativeLibDir, privateDataDir, l AppearancePath = filepath.Join(ConfDir, "appearance") ThemesPath = filepath.Join(AppearancePath, "themes") IconsPath = filepath.Join(AppearancePath, "icons") + SnippetsPath = filepath.Join(DataDir, "snippets") Resident = true ServerPort = FixedPort Container = container