feat: 增加环境预检查与多根目录支持,调整构建操作布局
This commit is contained in:
1 parent
2cb70beb69
commit
7984785610
17 files changed
+852
-97
No files matched your search
+34
-21
@@ -25,6 +25,7 @@ type GitSnapshot struct {
|
||||
type WorkspaceRequest struct {
|
||||
WorkspacePath string `json:"workspacePath"`
|
||||
ProjectID string `json:"projectId,omitempty"`
|
||||
JavaHome string `json:"javaHome,omitempty"`
|
||||
Git *GitSnapshot `json:"git,omitempty"`
|
||||
}
|
||||
|
||||
@@ -158,14 +159,6 @@ func (s *Server) validateWorkspace(path string) (string, error) {
|
||||
if !filepath.IsAbs(path) {
|
||||
return "", fmt.Errorf("请填写服务端已有文件夹的绝对路径")
|
||||
}
|
||||
root := s.workspaceRoot
|
||||
if root == "" {
|
||||
root = filepath.Join(s.root, "projects")
|
||||
}
|
||||
root, e := filepath.Abs(root)
|
||||
if e != nil {
|
||||
return "", e
|
||||
}
|
||||
path = filepath.Clean(path)
|
||||
dataRel, dataErr := filepath.Rel(s.root, path)
|
||||
if dataErr == nil && dataRel != ".." && !strings.HasPrefix(dataRel, ".."+string(filepath.Separator)) {
|
||||
@@ -174,9 +167,8 @@ func (s *Server) validateWorkspace(path string) (string, error) {
|
||||
return "", fmt.Errorf("不能选择服务数据或元数据目录;旧工作区请精确选择 projects/<id>/work")
|
||||
}
|
||||
}
|
||||
rel, e := filepath.Rel(root, path)
|
||||
if e != nil || rel == "." || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||
return "", fmt.Errorf("远程文件夹必须位于管理员允许的根目录内:%s", root)
|
||||
if _, ok := s.containingWorkspaceRoot(path, false); !ok {
|
||||
return "", fmt.Errorf("远程文件夹必须位于管理员允许的根目录内:%s", strings.Join(s.allowedWorkspaceRoots(), ", "))
|
||||
}
|
||||
// Reject both final and ancestor symlink/junction redirection.
|
||||
for current := path; ; current = filepath.Dir(current) {
|
||||
@@ -203,21 +195,26 @@ func (s *Server) validateWorkspace(path string) (string, error) {
|
||||
|
||||
// Directory browsing is confined to the administrator's root. Files are never listed.
|
||||
func (s *Server) browseDirectories(w http.ResponseWriter, r *http.Request) {
|
||||
root := s.workspaceRoot
|
||||
if root == "" {
|
||||
root = filepath.Join(s.root, "projects")
|
||||
}
|
||||
root, _ = filepath.Abs(root)
|
||||
roots := s.allowedWorkspaceRoots()
|
||||
path := r.URL.Query().Get("path")
|
||||
if len(roots) > 1 && (path == "" || path == "@roots") {
|
||||
dirs := []map[string]string{}
|
||||
for _, root := range roots {
|
||||
dirs = append(dirs, map[string]string{"name": root, "path": root})
|
||||
}
|
||||
jsonOut(w, map[string]any{"path": "", "root": "", "roots": roots, "parent": "", "selectable": false, "directories": dirs, "limit": 1000})
|
||||
return
|
||||
}
|
||||
if path == "" {
|
||||
path = root
|
||||
path = roots[0]
|
||||
}
|
||||
path = filepath.Clean(path)
|
||||
rel, e := filepath.Rel(root, path)
|
||||
if e != nil || !filepath.IsAbs(path) || rel == ".." || strings.HasPrefix(rel, ".."+string(filepath.Separator)) {
|
||||
root, ok := s.containingWorkspaceRoot(path, true)
|
||||
if !ok {
|
||||
http.Error(w, "目录超出管理员允许的根目录", 400)
|
||||
return
|
||||
}
|
||||
rel, _ := filepath.Rel(root, path)
|
||||
resolved, e := filepath.EvalSymlinks(path)
|
||||
if e != nil || !strings.EqualFold(filepath.Clean(resolved), path) {
|
||||
http.Error(w, "目录不存在或经过链接重定向", 400)
|
||||
@@ -240,9 +237,11 @@ func (s *Server) browseDirectories(w http.ResponseWriter, r *http.Request) {
|
||||
parent := ""
|
||||
if rel != "." {
|
||||
parent = filepath.Dir(path)
|
||||
} else if len(roots) > 1 {
|
||||
parent = "@roots"
|
||||
}
|
||||
_, selectErr := s.validateWorkspace(path)
|
||||
jsonOut(w, map[string]any{"path": path, "root": root, "parent": parent, "selectable": selectErr == nil, "directories": dirs, "limit": 1000})
|
||||
jsonOut(w, map[string]any{"path": path, "root": root, "roots": roots, "parent": parent, "selectable": selectErr == nil, "directories": dirs, "limit": 1000})
|
||||
}
|
||||
func gitCommand(work string, input []byte, args ...string) ([]byte, error) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
@@ -440,7 +439,21 @@ func (s *Server) checkWorkspace(w http.ResponseWriter, r *http.Request) {
|
||||
if e != nil {
|
||||
message = e.Error()
|
||||
}
|
||||
jsonOut(w, map[string]any{"workspacePath": path, "git": remote, "canSync": e == nil, "message": message})
|
||||
var report Preflight
|
||||
if pr := s.projects[req.ProjectID]; pr != nil && pr.Busy {
|
||||
report = Preflight{Ready: false, Items: []CheckItem{{Name: "工作区", Status: "error", Path: path, Message: "工作区正在构建,暂不执行写入探针"}}}
|
||||
} else {
|
||||
cfg, configErr := s.buildEnvironment()
|
||||
if configErr == nil && req.JavaHome != "" {
|
||||
cfg.JavaHome, configErr = s.selectedJDK(req.JavaHome)
|
||||
}
|
||||
if configErr != nil {
|
||||
report = Preflight{Items: []CheckItem{{Name: "环境配置", Status: "error", Message: configErr.Error()}}}
|
||||
} else {
|
||||
report = s.preflight(path, cfg)
|
||||
}
|
||||
}
|
||||
jsonOut(w, map[string]any{"workspacePath": path, "git": remote, "canSync": e == nil, "message": message, "preflight": report})
|
||||
}
|
||||
func (s *Server) createProject(w http.ResponseWriter, r *http.Request) {
|
||||
var req WorkspaceRequest
|
||||
|
||||
Reference in new issue
Block a user