From b2803f574b83589c9c0fed8a43eda7c3e469b58b Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Thu, 27 Nov 2025 17:59:48 +0800 Subject: [PATCH] chore: Remove some unused code (#11105) --- agent/app/api/v2/database_mysql.go | 18 --------------- .../client/helper/webdav/auth.go | 18 --------------- .../client/helper/webdav/utils.go | 8 ------- core/app/api/v2/auth.go | 9 -------- core/app/api/v2/upgrade.go | 22 ------------------- core/app/repo/common.go | 5 ----- core/app/repo/host.go | 6 ----- core/app/service/host.go | 4 ++-- .../client/helper/webdav/auth.go | 18 --------------- .../client/helper/webdav/utils.go | 8 ------- core/utils/common/sqlite.go | 19 ---------------- 11 files changed, 2 insertions(+), 133 deletions(-) diff --git a/agent/app/api/v2/database_mysql.go b/agent/app/api/v2/database_mysql.go index 12a31fa2c..6469adf9e 100644 --- a/agent/app/api/v2/database_mysql.go +++ b/agent/app/api/v2/database_mysql.go @@ -194,24 +194,6 @@ func (b *BaseApi) SearchMysql(c *gin.Context) { }) } -// @Tags Database Mysql -// @Summary List mysql database names -// @Accept json -// @Param request body dto.PageInfo true "request" -// @Success 200 {array} dto.MysqlOption -// @Security ApiKeyAuth -// @Security Timestamp -// @Router /databases/options [get] -func (b *BaseApi) ListDBName(c *gin.Context) { - list, err := mysqlService.ListDBOption() - if err != nil { - helper.InternalServer(c, err) - return - } - - helper.SuccessWithData(c, list) -} - // @Tags Database Mysql // @Summary List mysql database format collation options // @Accept json diff --git a/agent/utils/cloud_storage/client/helper/webdav/auth.go b/agent/utils/cloud_storage/client/helper/webdav/auth.go index b96ce0450..d20218d1e 100644 --- a/agent/utils/cloud_storage/client/helper/webdav/auth.go +++ b/agent/utils/cloud_storage/client/helper/webdav/auth.go @@ -72,16 +72,6 @@ func NewAutoAuth(login string, secret string) Authorizer { return az } -func NewEmptyAuth() Authorizer { - fmap := make([]authfactory, 0) - az := &authorizer{factories: fmap, defAuthMux: sync.Mutex{}, defAuth: &nullAuth{}} - return az -} - -func NewPreemptiveAuth(auth Authenticator) Authorizer { - return &preemptiveAuthorizer{auth: auth} -} - func (a *authorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) { var retryBuf io.Reader = body if body != nil { @@ -296,11 +286,3 @@ func (n *nullAuth) Clone() Authenticator { func (n *nullAuth) String() string { return "NullAuth" } - -func (b *preemptiveAuthorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) { - return b.auth.Clone(), body -} - -func (b *preemptiveAuthorizer) AddAuthenticator(key string, fn AuthFactory) { - panic("You're funny! A preemptive authorizer may only have a single authentication method") -} diff --git a/agent/utils/cloud_storage/client/helper/webdav/utils.go b/agent/utils/cloud_storage/client/helper/webdav/utils.go index 129018ff7..a6b7d4709 100644 --- a/agent/utils/cloud_storage/client/helper/webdav/utils.go +++ b/agent/utils/cloud_storage/client/helper/webdav/utils.go @@ -1,7 +1,6 @@ package webdav import ( - "bytes" "encoding/xml" "io" "net/url" @@ -63,13 +62,6 @@ func Join(path0 string, path1 string) string { return strings.TrimSuffix(path0, "/") + "/" + strings.TrimPrefix(path1, "/") } -func String(r io.Reader) string { - buf := new(bytes.Buffer) - // TODO - make String return an error as well - _, _ = buf.ReadFrom(r) - return buf.String() -} - func parseInt64(s *string) int64 { if n, e := strconv.ParseInt(*s, 10, 64); e == nil { return n diff --git a/core/app/api/v2/auth.go b/core/app/api/v2/auth.go index c2b60d9a9..717beac96 100644 --- a/core/app/api/v2/auth.go +++ b/core/app/api/v2/auth.go @@ -118,15 +118,6 @@ func (b *BaseApi) Captcha(c *gin.Context) { helper.SuccessWithData(c, captcha) } -func (b *BaseApi) GetResponsePage(c *gin.Context) { - pageCode, err := authService.GetResponsePage() - if err != nil { - helper.InternalServer(c, err) - return - } - helper.SuccessWithData(c, pageCode) -} - func (b *BaseApi) GetWelcomePage(c *gin.Context) { count, _, _ := logService.PageLoginLog(c, dto.SearchLgLogWithPage{PageInfo: dto.PageInfo{Page: 1, PageSize: 10}}) if count != 1 { diff --git a/core/app/api/v2/upgrade.go b/core/app/api/v2/upgrade.go index dc951afff..22e3fb46e 100644 --- a/core/app/api/v2/upgrade.go +++ b/core/app/api/v2/upgrade.go @@ -79,25 +79,3 @@ func (b *BaseApi) Upgrade(c *gin.Context) { } helper.Success(c) } - -// @Tags System Setting -// @Summary Upgrade -// @Accept json -// @Param request body dto.OperateByID true "request" -// @Success 200 -// @Security ApiKeyAuth -// @Security Timestamp -// @Router /core/settings/rollback [post] -// @x-panel-log {"bodyKeys":["id"],"paramKeys":[],"BeforeFunctions":[{"input_column":"id","input_value":"id","isList":false,"db":"upgrade_logs","output_column":"old_version","output_value":"version"}],"formatZH":"回滚系统 => [version]","formatEN":"rollback system => [version]"} -func (b *BaseApi) Rollback(c *gin.Context) { - var req dto.OperateByID - if err := helper.CheckBindAndValidate(&req, c); err != nil { - return - } - - if err := upgradeService.Rollback(req); err != nil { - helper.InternalServer(c, err) - return - } - helper.Success(c) -} diff --git a/core/app/repo/common.go b/core/app/repo/common.go index 0b3046609..aad17fe10 100644 --- a/core/app/repo/common.go +++ b/core/app/repo/common.go @@ -60,11 +60,6 @@ func WithByNode(node string) global.DBOption { return g.Where("node = ?", node) } } -func WithByGroupBelong(group string) global.DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("group_belong = ?", group) - } -} func WithOrderBy(orderStr string) global.DBOption { if orderStr == "createdAt" { diff --git a/core/app/repo/host.go b/core/app/repo/host.go index a0066a02a..fc029c866 100644 --- a/core/app/repo/host.go +++ b/core/app/repo/host.go @@ -20,7 +20,6 @@ type IHostRepo interface { WithByInfo(info string) global.DBOption WithByPort(port uint) global.DBOption WithByUser(user string) global.DBOption - WithByAddr(addr string) global.DBOption } func NewIHostRepo() IHostRepo { @@ -79,11 +78,6 @@ func (h *HostRepo) WithByUser(user string) global.DBOption { return g.Where("user = ?", user) } } -func (h *HostRepo) WithByAddr(addr string) global.DBOption { - return func(g *gorm.DB) *gorm.DB { - return g.Where("addr = ?", addr) - } -} func (h *HostRepo) Create(host *model.Host) error { return global.DB.Create(host).Error diff --git a/core/app/service/host.go b/core/app/service/host.go index 3fcc2326f..9a7b15516 100644 --- a/core/app/service/host.go +++ b/core/app/service/host.go @@ -50,7 +50,7 @@ func (u *HostService) TestByInfo(req dto.HostConnTest) bool { req.PrivateKey = string(privateKey) } if len(req.Password) == 0 && len(req.PrivateKey) == 0 { - host, err := hostRepo.Get(hostRepo.WithByAddr(req.Addr), hostRepo.WithByPort(req.Port)) + host, err := hostRepo.Get(repo.WithByAddr(req.Addr), hostRepo.WithByPort(req.Port)) if err != nil { return false } @@ -235,7 +235,7 @@ func (u *HostService) GetHostByID(id uint) (*dto.HostInfo, error) { } func (u *HostService) Create(req dto.HostOperate) (*dto.HostInfo, error) { - hostItem, _ := hostRepo.Get(hostRepo.WithByAddr(req.Addr), hostRepo.WithByUser(req.User), hostRepo.WithByPort(req.Port)) + hostItem, _ := hostRepo.Get(repo.WithByAddr(req.Addr), hostRepo.WithByUser(req.User), hostRepo.WithByPort(req.Port)) if hostItem.ID != 0 { return nil, buserr.New("ErrRecordExist") } diff --git a/core/utils/cloud_storage/client/helper/webdav/auth.go b/core/utils/cloud_storage/client/helper/webdav/auth.go index b96ce0450..d20218d1e 100644 --- a/core/utils/cloud_storage/client/helper/webdav/auth.go +++ b/core/utils/cloud_storage/client/helper/webdav/auth.go @@ -72,16 +72,6 @@ func NewAutoAuth(login string, secret string) Authorizer { return az } -func NewEmptyAuth() Authorizer { - fmap := make([]authfactory, 0) - az := &authorizer{factories: fmap, defAuthMux: sync.Mutex{}, defAuth: &nullAuth{}} - return az -} - -func NewPreemptiveAuth(auth Authenticator) Authorizer { - return &preemptiveAuthorizer{auth: auth} -} - func (a *authorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) { var retryBuf io.Reader = body if body != nil { @@ -296,11 +286,3 @@ func (n *nullAuth) Clone() Authenticator { func (n *nullAuth) String() string { return "NullAuth" } - -func (b *preemptiveAuthorizer) NewAuthenticator(body io.Reader) (Authenticator, io.Reader) { - return b.auth.Clone(), body -} - -func (b *preemptiveAuthorizer) AddAuthenticator(key string, fn AuthFactory) { - panic("You're funny! A preemptive authorizer may only have a single authentication method") -} diff --git a/core/utils/cloud_storage/client/helper/webdav/utils.go b/core/utils/cloud_storage/client/helper/webdav/utils.go index 129018ff7..a6b7d4709 100644 --- a/core/utils/cloud_storage/client/helper/webdav/utils.go +++ b/core/utils/cloud_storage/client/helper/webdav/utils.go @@ -1,7 +1,6 @@ package webdav import ( - "bytes" "encoding/xml" "io" "net/url" @@ -63,13 +62,6 @@ func Join(path0 string, path1 string) string { return strings.TrimSuffix(path0, "/") + "/" + strings.TrimPrefix(path1, "/") } -func String(r io.Reader) string { - buf := new(bytes.Buffer) - // TODO - make String return an error as well - _, _ = buf.ReadFrom(r) - return buf.String() -} - func parseInt64(s *string) int64 { if n, e := strconv.ParseInt(*s, 10, 64); e == nil { return n diff --git a/core/utils/common/sqlite.go b/core/utils/common/sqlite.go index 3922ad6ef..acb82387c 100644 --- a/core/utils/common/sqlite.go +++ b/core/utils/common/sqlite.go @@ -31,25 +31,6 @@ func LoadDBConnByPath(fullPath, dbName string) *gorm.DB { return db } -func LoadDBConnByPathWithErr(fullPath, dbName string) (*gorm.DB, error) { - if _, err := CreateDirWhenNotExist(true, path.Dir(fullPath)); err != nil { - return nil, fmt.Errorf("init db dir failed, err: %v", err) - } - if _, err := os.Stat(fullPath); err != nil { - f, err := os.Create(fullPath) - if err != nil { - return nil, fmt.Errorf("init %s db file failed, err: %v", dbName, err) - } - _ = f.Close() - } - - db, err := GetDBWithPath(fullPath) - if err != nil { - return nil, fmt.Errorf("init %s db failed, err: %v", dbName, err) - } - return db, nil -} - func CloseDB(db *gorm.DB) { sqlDB, err := db.DB() if err != nil {