优化:工具栏高度对齐+面板统一+远程连接架构+自动恢复预览
- 工具栏:面包屑与右侧组件像素级等高(:deep 34px)、合并重复search handler、统一分隔符样式、删除死代码 - 面板对齐:三面板header统一padding/font-size、文件列表分页固定底部(自定义紧凑)、表头默认隐藏、滚动条统一样式 - 预览区:始终显示空白预览面板、重启自动恢复上次打开文件 - 收藏夹:简化计数显示(共N项) - 远程连接:ConnectionIndicator自适应UI(无远程显示mini云图标)、ConnectionDialog支持编辑配置、transport抽象层(本地Wails/远程HTTP双模式)、agent后端模块
This commit is contained in:
113
internal/agent/handler/system_handler.go
Normal file
113
internal/agent/handler/system_handler.go
Normal file
@@ -0,0 +1,113 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"u-desk/internal/agent/model"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
|
||||
// Ping 健康检查
|
||||
func (h *Handler) Ping(c echo.Context) error {
|
||||
return c.JSON(http.StatusOK, model.OK(map[string]string{
|
||||
"status": "ok",
|
||||
}))
|
||||
}
|
||||
|
||||
// Info 返回 Agent 信息
|
||||
func (h *Handler) Info(c echo.Context) error {
|
||||
hostname, _ := os.Hostname()
|
||||
return c.JSON(http.StatusOK, model.OK(map[string]interface{}{
|
||||
"version": "0.1.0",
|
||||
"os": runtime.GOOS,
|
||||
"arch": runtime.GOARCH,
|
||||
"hostname": hostname,
|
||||
}))
|
||||
}
|
||||
|
||||
// CommonPaths 返回常用系统路径
|
||||
func (h *Handler) CommonPaths(c echo.Context) error {
|
||||
paths := map[string]string{}
|
||||
|
||||
home, _ := os.UserHomeDir()
|
||||
if home != "" {
|
||||
paths["home"] = home
|
||||
paths["desktop"] = home + "/Desktop"
|
||||
paths["documents"] = home + "/Documents"
|
||||
paths["downloads"] = home + "/Downloads"
|
||||
}
|
||||
|
||||
// 根据平台添加盘符/根路径
|
||||
if runtime.GOOS == "windows" {
|
||||
for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
|
||||
_, err := os.Stat(string(drive) + ":\\")
|
||||
if err == nil {
|
||||
paths["drive_"+strings.ToLower(string(drive))] = string(drive) + ":\\"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
paths["root"] = "/"
|
||||
_, err := os.Stat("/home")
|
||||
if err == nil {
|
||||
paths["users"] = "/home"
|
||||
}
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, model.OK(paths))
|
||||
}
|
||||
|
||||
// Drives 返回可用磁盘列表
|
||||
func (h *Handler) Drives(c echo.Context) error {
|
||||
type DriveInfo struct {
|
||||
Name string `json:"name"`
|
||||
Path string `json:"path"`
|
||||
FsType string `json:"fs_type,omitempty"`
|
||||
Total uint64 `json:"total"`
|
||||
Free uint64 `json:"free"`
|
||||
}
|
||||
|
||||
var drives []DriveInfo
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
for _, drive := range "ABCDEFGHIJKLMNOPQRSTUVWXYZ" {
|
||||
drivePath := string(drive) + ":\\"
|
||||
if _, err := os.Stat(drivePath); err != nil {
|
||||
continue
|
||||
}
|
||||
drives = append(drives, DriveInfo{
|
||||
Name: strings.ToLower(string(drive)),
|
||||
Path: drivePath,
|
||||
Total: 0,
|
||||
Free: 0,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
parts, err := os.ReadDir("/")
|
||||
if err == nil {
|
||||
for _, p := range parts {
|
||||
name := p.Name()
|
||||
if len(name) == 2 && name[0] != '.' && name[1] != '.' && p.IsDir() {
|
||||
// 可能是挂载点
|
||||
fullPath := "/" + name
|
||||
if stat, err := os.Stat(fullPath); err == nil && stat.IsDir() {
|
||||
drives = append(drives, DriveInfo{
|
||||
Name: name,
|
||||
Path: fullPath,
|
||||
})
|
||||
_ = stat
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 至少返回根目录
|
||||
if len(drives) == 0 {
|
||||
drives = append(drives, DriveInfo{Name: "/", Path: "/"})
|
||||
}
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, model.OK(drives))
|
||||
}
|
||||
Reference in New Issue
Block a user