fix: windows

This commit is contained in:
2025-02-20 12:18:40 +07:00
parent b406d68abb
commit cd197abd90

View File

@@ -1,9 +1,9 @@
package utils package utils
import ( import (
"errors" "errors"
"os" "os"
"path/filepath" "path/filepath"
) )
func FindFrontendPath() string { func FindFrontendPath() string {
@@ -13,7 +13,7 @@ func FindFrontendPath() string {
} }
var dirs []string var dirs []string
for currentPath != "/" { for currentPath != filepath.VolumeName(currentPath)+string(os.PathSeparator) {
dir, file := filepath.Split(currentPath) dir, file := filepath.Split(currentPath)
if file != "" { if file != "" {
dirs = append([]string{file}, dirs...) dirs = append([]string{file}, dirs...)
@@ -21,7 +21,7 @@ func FindFrontendPath() string {
currentPath = filepath.Clean(dir) currentPath = filepath.Clean(dir)
} }
if len(dirs) < 2 || dirs[len(dirs)-2] + "/" + dirs[len(dirs)-1] != "frontend/src" { if len(dirs) < 2 || filepath.Join(dirs[len(dirs)-2], dirs[len(dirs)-1]) != filepath.Join("frontend", "src") {
panic(errors.New("You're not in frontend/src")) panic(errors.New("You're not in frontend/src"))
} }
@@ -31,13 +31,15 @@ func FindFrontendPath() string {
break break
} }
if i > 0 { if i > 0 {
dir = "/" + dir path = filepath.Join(path, dir)
} else {
path = dir
} }
path += dir
} }
if dirs[0] == "home" { if filepath.VolumeName(path) == "" {
path = "/" + path path = filepath.Join(string(os.PathSeparator), path)
} }
return path return path
} }