mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-10-09 15:06:37 +08:00
feat: add rsync check for file exchange (#10317)
This commit is contained in:
parent
d21f4ffae6
commit
2258ba108d
7 changed files with 82 additions and 0 deletions
|
@ -38,6 +38,7 @@ var (
|
||||||
sshService = service.NewISSHService()
|
sshService = service.NewISSHService()
|
||||||
firewallService = service.NewIFirewallService()
|
firewallService = service.NewIFirewallService()
|
||||||
monitorService = service.NewIMonitorService()
|
monitorService = service.NewIMonitorService()
|
||||||
|
systemService = service.NewISystemService()
|
||||||
|
|
||||||
deviceService = service.NewIDeviceService()
|
deviceService = service.NewIDeviceService()
|
||||||
fail2banService = service.NewIFail2BanService()
|
fail2banService = service.NewIFail2BanService()
|
||||||
|
|
26
agent/app/api/v2/system.go
Normal file
26
agent/app/api/v2/system.go
Normal 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)
|
||||||
|
}
|
8
agent/app/dto/response/system.go
Normal file
8
agent/app/dto/response/system.go
Normal 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"`
|
||||||
|
}
|
29
agent/app/service/system.go
Normal file
29
agent/app/service/system.go
Normal 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
|
||||||
|
}
|
|
@ -57,5 +57,7 @@ func (s *HostRouter) InitRouter(Router *gin.RouterGroup) {
|
||||||
hostRouter.POST("/disks/partition", baseApi.PartitionDisk)
|
hostRouter.POST("/disks/partition", baseApi.PartitionDisk)
|
||||||
hostRouter.POST("/disks/mount", baseApi.MountDisk)
|
hostRouter.POST("/disks/mount", baseApi.MountDisk)
|
||||||
hostRouter.POST("/disks/unmount", baseApi.UnmountDisk)
|
hostRouter.POST("/disks/unmount", baseApi.UnmountDisk)
|
||||||
|
|
||||||
|
hostRouter.GET("/components/:name", baseApi.CheckComponentExistence)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -251,4 +251,11 @@ export namespace Host {
|
||||||
export interface DiskUmount {
|
export interface DiskUmount {
|
||||||
mountPoint: string;
|
mountPoint: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface ComponentInfo {
|
||||||
|
exists: boolean;
|
||||||
|
version: string;
|
||||||
|
path: string;
|
||||||
|
error: string;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -124,3 +124,12 @@ export const mountDisk = (params: Host.DiskMount) => {
|
||||||
export const unmountDisk = (params: Host.DiskUmount) => {
|
export const unmountDisk = (params: Host.DiskUmount) => {
|
||||||
return http.post(`/hosts/disks/unmount`, params, TimeoutEnum.T_60S);
|
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}`);
|
||||||
|
};
|
||||||
|
|
Loading…
Add table
Reference in a new issue