Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
trheyi committed Oct 8, 2021
1 parent 5410f2e commit 9c4cf8a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 5 deletions.
9 changes: 8 additions & 1 deletion global/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
27 changes: 23 additions & 4 deletions xfs/xfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions xiang/apis/xiang.http.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
]
}

0 comments on commit 9c4cf8a

Please sign in to comment.