mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-25 02:21:05 +01:00
chore: add ROOT_DIR environment variable, refactor
This commit is contained in:
@@ -27,7 +27,7 @@ func fileType(file string) FileType {
|
||||
switch {
|
||||
case strings.HasPrefix(path.Base(file), "config."):
|
||||
return FileTypeConfig
|
||||
case strings.HasPrefix(file, common.MiddlewareComposeBasePath):
|
||||
case strings.HasPrefix(file, common.MiddlewareComposeDir):
|
||||
return FileTypeMiddleware
|
||||
}
|
||||
return FileTypeProvider
|
||||
@@ -43,9 +43,9 @@ func (t FileType) IsValid() bool {
|
||||
|
||||
func (t FileType) GetPath(filename string) string {
|
||||
if t == FileTypeMiddleware {
|
||||
return path.Join(common.MiddlewareComposeBasePath, filename)
|
||||
return path.Join(common.MiddlewareComposeDir, filename)
|
||||
}
|
||||
return path.Join(common.ConfigBasePath, filename)
|
||||
return path.Join(common.ConfigDir, filename)
|
||||
}
|
||||
|
||||
func getArgs(r *http.Request) (fileType FileType, filename string, err error) {
|
||||
|
||||
@@ -94,7 +94,7 @@ func listRoute(which string) any {
|
||||
}
|
||||
|
||||
func listFiles(w http.ResponseWriter, r *http.Request) {
|
||||
files, err := utils.ListFiles(common.ConfigBasePath, 0, true)
|
||||
files, err := utils.ListFiles(common.ConfigDir, 0, true)
|
||||
if err != nil {
|
||||
gphttp.ServerError(w, r, err)
|
||||
return
|
||||
@@ -107,17 +107,17 @@ func listFiles(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
for _, file := range files {
|
||||
t := fileType(file)
|
||||
file = strings.TrimPrefix(file, common.ConfigBasePath+"/")
|
||||
file = strings.TrimPrefix(file, common.ConfigDir+"/")
|
||||
resp[t] = append(resp[t], file)
|
||||
}
|
||||
|
||||
mids, err := utils.ListFiles(common.MiddlewareComposeBasePath, 0, true)
|
||||
mids, err := utils.ListFiles(common.MiddlewareComposeDir, 0, true)
|
||||
if err != nil {
|
||||
gphttp.ServerError(w, r, err)
|
||||
return
|
||||
}
|
||||
for _, mid := range mids {
|
||||
mid = strings.TrimPrefix(mid, common.MiddlewareComposeBasePath+"/")
|
||||
mid = strings.TrimPrefix(mid, common.MiddlewareComposeDir+"/")
|
||||
resp[FileTypeMiddleware] = append(resp[FileTypeMiddleware], mid)
|
||||
}
|
||||
gphttp.RespondJSON(w, r, resp)
|
||||
|
||||
Reference in New Issue
Block a user