This commit is contained in:
robin
2026-03-13 14:25:13 +08:00
parent a25a474d6a
commit afbaaa869c
95 changed files with 4591 additions and 2578 deletions

View File

@@ -16,6 +16,8 @@ import (
"github.com/iwind/TeaGo/logs"
"github.com/iwind/TeaGo/maps"
"net/http"
"os"
"path/filepath"
)
type ComponentsAction actions.Action
@@ -41,12 +43,7 @@ func (this *ComponentsAction) RunGet(params struct{}) {
var buffer = bytes.NewBuffer([]byte{})
var webRoot string
if Tea.IsTesting() {
webRoot = Tea.Root + "/../web/public/js/components/"
} else {
webRoot = Tea.Root + "/web/public/js/components/"
}
webRoot := findComponentsRoot()
f := files.NewFile(webRoot)
f.Range(func(file *files.File) {
@@ -173,3 +170,27 @@ func (this *ComponentsAction) RunGet(params struct{}) {
_, _ = this.Write(componentsData)
}
func findComponentsRoot() string {
candidates := []string{
filepath.Join(Tea.Root, "web", "public", "js", "components"),
filepath.Join(Tea.Root, "..", "web", "public", "js", "components"),
filepath.Join(Tea.Root, "..", "..", "web", "public", "js", "components"),
}
if cwd, err := os.Getwd(); err == nil && len(cwd) > 0 {
candidates = append(candidates,
filepath.Join(cwd, "web", "public", "js", "components"),
filepath.Join(cwd, "EdgeAdmin", "web", "public", "js", "components"),
)
}
for _, candidate := range candidates {
info, err := os.Stat(candidate)
if err == nil && info.IsDir() {
return candidate + string(filepath.Separator)
}
}
return filepath.Join(Tea.Root, "web", "public", "js", "components") + string(filepath.Separator)
}