feat: add rsync check for file exchange (#10317)

This commit is contained in:
CityFun 2025-09-09 16:38:44 +08:00 committed by GitHub
parent d21f4ffae6
commit 2258ba108d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 82 additions and 0 deletions

View file

@ -38,6 +38,7 @@ var (
sshService = service.NewISSHService()
firewallService = service.NewIFirewallService()
monitorService = service.NewIMonitorService()
systemService = service.NewISystemService()
deviceService = service.NewIDeviceService()
fail2banService = service.NewIFail2BanService()

View file

@ -0,0 +1,26 @@
package v2
import (
"errors"
"github.com/1Panel-dev/1Panel/agent/app/api/v2/helper"
"github.com/gin-gonic/gin"
)
// @Tags Host
// @Summary Check if a system component exists
// @Accept json
// @Param name query string true "Component name to check (e.g., rsync, docker)"
// @Success 200 {object} response.ComponentInfo
// @Security ApiKeyAuth
// @Security Timestamp
// @Router /hosts/components/{name} [get]
func (b *BaseApi) CheckComponentExistence(c *gin.Context) {
name := c.Param("name")
if name == "" {
helper.BadRequest(c, errors.New("empty component name"))
return
}
info := systemService.IsComponentExist(name)
helper.SuccessWithData(c, info)
}

View file

@ -0,0 +1,8 @@
package response
type ComponentInfo struct {
Exists bool `json:"exists"`
Version string `json:"version"`
Path string `json:"path"`
Error string `json:"error"`
}

View file

@ -0,0 +1,29 @@
package service
import (
"github.com/1Panel-dev/1Panel/agent/app/dto/response"
"os/exec"
)
type SystemService struct{}
type ISystemService interface {
IsComponentExist(name string) response.ComponentInfo
}
func NewISystemService() ISystemService {
return &SystemService{}
}
func (s *SystemService) IsComponentExist(name string) response.ComponentInfo {
info := response.ComponentInfo{}
path, err := exec.LookPath(name)
if err != nil {
info.Exists = false
info.Error = err.Error()
return info
}
info.Exists = true
info.Path = path
return info
}

View file

@ -57,5 +57,7 @@ func (s *HostRouter) InitRouter(Router *gin.RouterGroup) {
hostRouter.POST("/disks/partition", baseApi.PartitionDisk)
hostRouter.POST("/disks/mount", baseApi.MountDisk)
hostRouter.POST("/disks/unmount", baseApi.UnmountDisk)
hostRouter.GET("/components/:name", baseApi.CheckComponentExistence)
}
}

View file

@ -251,4 +251,11 @@ export namespace Host {
export interface DiskUmount {
mountPoint: string;
}
export interface ComponentInfo {
exists: boolean;
version: string;
path: string;
error: string;
}
}

View file

@ -124,3 +124,12 @@ export const mountDisk = (params: Host.DiskMount) => {
export const unmountDisk = (params: Host.DiskUmount) => {
return http.post(`/hosts/disks/unmount`, params, TimeoutEnum.T_60S);
};
export const getComponentInfo = (name: string, operateNode?: string) => {
if (operateNode) {
return http.get<Host.ComponentInfo>(`/hosts/components/${name}`, {
CurrentNode: operateNode,
});
}
return http.get<Host.ComponentInfo>(`/hosts/components/${name}`);
};