From 9c4cf8a5ffa0d04f2fdd2ad2f8d6892225f872ad Mon Sep 17 00:00:00 2001 From: Max Date: Fri, 8 Oct 2021 21:27:24 +0800 Subject: [PATCH] fix bug --- global/process.go | 9 ++++++++- xfs/xfs.go | 27 +++++++++++++++++++++++---- xiang/apis/xiang.http.json | 11 +++++++++++ 3 files changed, 42 insertions(+), 5 deletions(-) diff --git a/global/process.go b/global/process.go index 37ee332853..a428c96b3e 100644 --- a/global/process.go +++ b/global/process.go @@ -11,6 +11,7 @@ func init() { gou.RegisterProcessHandler("xiang.global.FileContent", processFileContent) gou.RegisterProcessHandler("xiang.global.AppFileContent", processAppFileContent) gou.RegisterProcessHandler("xiang.global.Inspect", processInspect) + gou.RegisterProcessHandler("xiang.global.Favicon", processFavicon) } // processCreate 运行模型 MustCreate @@ -25,11 +26,17 @@ func processPing(process *gou.Process) interface{} { return res } -// processCreate 运行模型 MustCreate +// processInspect 返回系统信息 func processInspect(process *gou.Process) interface{} { + App.Icons["favicon"] = "/api/xiang/favicon.ico" return App } +// processFavicon 运行模型 MustCreate +func processFavicon(process *gou.Process) interface{} { + return xfs.DecodeString(App.Icons["png"]) +} + // processFileContent 返回文件内容 func processFileContent(process *gou.Process) interface{} { process.ValidateArgNums(2) diff --git a/xfs/xfs.go b/xfs/xfs.go index feb43c3ba1..d591e365ba 100644 --- a/xfs/xfs.go +++ b/xfs/xfs.go @@ -66,10 +66,10 @@ func New(path string) Xfs { exception.New("尚未支持 %s 文件系统", 500, fs).Throw() } - exists := xfs.MustDirExists("/") - if !exists { - xfs.MustMkdirAll("/", os.ModePerm) - } + // exists := xfs.MustDirExists("/") + // if !exists && root != "/" { + // xfs.MustMkdirAll("/", os.ModePerm) + // } return xfs } @@ -105,6 +105,25 @@ func Encode(content []byte) string { return base64.StdEncoding.EncodeToString(content) } +// Decode Base64编码 +func Decode(content []byte) []byte { + var data []byte + _, err := base64.StdEncoding.Decode(data, content) + if err != nil { + exception.New("文件解码失败 %s ", 500, err).Throw() + } + return data +} + +// DecodeString Base64编码 +func DecodeString(content string) string { + dst, err := base64.StdEncoding.DecodeString(content) + if err != nil { + exception.New("文件解码失败 %s ", 500, err).Throw() + } + return string(dst) +} + // MustOpen 打开文件 func (xfs *Xfs) MustOpen(filename string) File { file, err := xfs.Open(filename) diff --git a/xiang/apis/xiang.http.json b/xiang/apis/xiang.http.json index 2993f28668..c051458637 100644 --- a/xiang/apis/xiang.http.json +++ b/xiang/apis/xiang.http.json @@ -26,6 +26,17 @@ "status": 200, "type": "application/json" } + }, + { + "path": "/favicon.ico", + "method": "GET", + "guard": "-", + "process": "xiang.global.Favicon", + "in": [], + "out": { + "status": 200, + "type": "image/x-icon" + } } ] }