Skip to content

Commit

Permalink
修复windows系统文件路径问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinnrry committed Jun 2, 2022
1 parent a64a765 commit b92326b
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"strings"
)

const Separator = "```"

type Config struct {
ApiServerPort int
AdminServerPort int
Expand Down
6 changes: 3 additions & 3 deletions services/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func UpsertApi(apiPath string, info *ApiInfo) error {
apiPath = "/" + apiPath
}

dataPath := strings.Replace(apiPath, "/", "|||", -1)
dataPath := strings.Replace(apiPath, "/", config.Separator, -1)

_ = os.MkdirAll(config.RunConfig.DataPath+dataPath, 0777)

Expand Down Expand Up @@ -48,7 +48,7 @@ func GetApiList() ([]apiItem, error) {
return nil, err
}
for _, file := range dirList {
apiPath := strings.Replace(file.Name(), "|||", "/", -1)
apiPath := strings.Replace(file.Name(), config.Separator, "/", -1)

if config.RunConfig.ApiServerPort != 80 {
api = append(api, apiItem{
Expand All @@ -67,7 +67,7 @@ func GetApiList() ([]apiItem, error) {
}

func DeleteApi(path string) error {
dataPath := strings.Replace(path, "/", "|||", -1)
dataPath := strings.Replace(path, "/", config.Separator, -1)
dirPath := config.RunConfig.DataPath + dataPath
return os.RemoveAll(dirPath)
}
2 changes: 1 addition & 1 deletion services/apiResponse.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type ApiInfo struct {
func GetApiInfo(apiPath string) (*ApiInfo, error) {
ret := &ApiInfo{}
// 加载设置文件
dataPath := strings.Replace(apiPath, "/", "|||", -1)
dataPath := strings.Replace(apiPath, "/", config.Separator, -1)
filePtr, err := os.Open(config.RunConfig.DataPath + dataPath + "/settings.json")
if err != nil {
return nil, errors.New("接口不存在")
Expand Down
24 changes: 23 additions & 1 deletion views/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,32 @@
} else {
alert(data.msg)
}
},"json");
}, "json");
},
getUrlKey: function (name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ""])[1].replace(/\+/g, '%20')) || null
}
},
created: function () {
let that = this;
let path = this.getUrlKey("path");

this.apiPath = path;

if (path != "") {
$.get("/apiDetail", {api: path}, function (ret) {
if (ret.success === 0) {
that.httpCode = ret.data.http_code;
that.wait = ret.data.wait;
that.methods = ret.data.method;
that.response = ret.data.response;
that.responseHead = ret.data.header;
that.script = ret.data.custom_function;
}
}, "json")
}


}
})

Expand Down

0 comments on commit b92326b

Please sign in to comment.