2
0
mirror of https://github.com/acepanel/panel.git synced 2026-02-04 10:17:17 +08:00

feat: 去掉重复的方法

This commit is contained in:
耗子
2024-11-04 02:33:15 +08:00
parent 2d35cbc176
commit bf8c832b32
10 changed files with 29 additions and 111 deletions

View File

@@ -7,6 +7,7 @@ import (
"strings"
"github.com/go-rat/chix"
"github.com/go-rat/utils/str"
"github.com/spf13/cast"
"github.com/TheTNB/panel/internal/app"
@@ -16,7 +17,6 @@ import (
"github.com/TheTNB/panel/pkg/io"
"github.com/TheTNB/panel/pkg/os"
"github.com/TheTNB/panel/pkg/shell"
"github.com/TheTNB/panel/pkg/str"
)
type Service struct {

View File

@@ -7,11 +7,11 @@ import (
"strings"
"github.com/go-rat/chix"
"github.com/go-rat/utils/str"
"github.com/TheTNB/panel/internal/service"
"github.com/TheTNB/panel/pkg/io"
"github.com/TheTNB/panel/pkg/shell"
"github.com/TheTNB/panel/pkg/str"
"github.com/TheTNB/panel/pkg/systemctl"
)

View File

@@ -15,7 +15,6 @@ import (
"github.com/TheTNB/panel/pkg/api"
"github.com/TheTNB/panel/pkg/apploader"
"github.com/TheTNB/panel/pkg/shell"
"github.com/TheTNB/panel/pkg/str"
)
type appRepo struct {
@@ -65,7 +64,7 @@ func (r *appRepo) UpdateExist(slug string) bool {
for channel := range slices.Values(item.Channels) {
if channel.Slug == installed.Channel {
current := str.FirstElement(channel.Subs)
current := collect.First(channel.Subs)
if current != nil && current.Version != installed.Version {
return true
}
@@ -168,7 +167,7 @@ func (r *appRepo) Install(channel, slug string) error {
}
shellUrl = ch.Install
shellChannel = ch.Slug
shellVersion = str.FirstElement(ch.Subs).Version
shellVersion = collect.First(ch.Subs).Version
break
}
}
@@ -278,7 +277,7 @@ func (r *appRepo) Update(slug string) error {
}
shellUrl = ch.Update
shellChannel = ch.Slug
shellVersion = str.FirstElement(ch.Subs).Version
shellVersion = collect.First(ch.Subs).Version
break
}
}

View File

@@ -7,13 +7,14 @@ import (
"strconv"
"time"
"github.com/go-rat/utils/str"
"github.com/TheTNB/panel/internal/app"
"github.com/TheTNB/panel/internal/biz"
"github.com/TheTNB/panel/internal/http/request"
"github.com/TheTNB/panel/pkg/io"
"github.com/TheTNB/panel/pkg/os"
"github.com/TheTNB/panel/pkg/shell"
"github.com/TheTNB/panel/pkg/str"
"github.com/TheTNB/panel/pkg/systemctl"
)
@@ -99,7 +100,7 @@ panel-cli cutoff clear -t website -f %s -s %d -p %s
if !io.Exists(shellLogDir) {
return errors.New("计划任务日志目录不存在")
}
shellFile := strconv.Itoa(int(time.Now().Unix())) + str.RandomString(16)
shellFile := strconv.Itoa(int(time.Now().Unix())) + str.Random(16)
if err := io.Write(filepath.Join(shellDir, shellFile+".sh"), script, 0700); err != nil {
return errors.New(err.Error())
}

View File

@@ -7,7 +7,9 @@ import (
"path/filepath"
"time"
"github.com/go-rat/utils/collect"
"github.com/go-rat/utils/hash"
"github.com/go-rat/utils/str"
"github.com/spf13/cast"
"github.com/urfave/cli/v3"
"gopkg.in/yaml.v3"
@@ -21,7 +23,6 @@ import (
"github.com/TheTNB/panel/pkg/cert"
"github.com/TheTNB/panel/pkg/io"
"github.com/TheTNB/panel/pkg/ntp"
"github.com/TheTNB/panel/pkg/str"
"github.com/TheTNB/panel/pkg/systemctl"
"github.com/TheTNB/panel/pkg/tools"
"github.com/TheTNB/panel/pkg/types"
@@ -84,7 +85,7 @@ func (s *CliService) Update(ctx context.Context, cmd *cli.Command) error {
return fmt.Errorf("获取最新版本失败:%v", err)
}
download := str.FirstElement(panel.Downloads)
download := collect.First(panel.Downloads)
if download == nil {
return fmt.Errorf("下载地址为空")
}
@@ -103,15 +104,15 @@ func (s *CliService) Info(ctx context.Context, cmd *cli.Command) error {
return fmt.Errorf("获取管理员信息失败:%v", err)
}
password := str.RandomString(16)
password := str.Random(16)
hashed, err := s.hash.Make(password)
if err != nil {
return fmt.Errorf("密码生成失败:%v", err)
}
user.Username = str.RandomString(8)
user.Username = str.Random(8)
user.Password = hashed
if user.Email == "" {
user.Email = str.RandomString(8) + "@example.com"
user.Email = str.Random(8) + "@example.com"
}
if err = app.Orm.Save(user).Error; err != nil {
@@ -326,7 +327,7 @@ func (s *CliService) EntranceOn(ctx context.Context, cmd *cli.Command) error {
return err
}
config.HTTP.Entrance = "/" + str.RandomString(6)
config.HTTP.Entrance = "/" + str.Random(6)
encoded, err := yaml.Marshal(config)
if err != nil {
@@ -755,7 +756,7 @@ func (s *CliService) Init(ctx context.Context, cmd *cli.Command) error {
return fmt.Errorf("初始化失败:%v", err)
}
value, err := hash.NewArgon2id().Make(str.RandomString(32))
value, err := hash.NewArgon2id().Make(str.Random(32))
if err != nil {
return fmt.Errorf("初始化失败:%v", err)
}
@@ -779,8 +780,8 @@ func (s *CliService) Init(ctx context.Context, cmd *cli.Command) error {
return err
}
config.App.Key = str.RandomString(32)
config.HTTP.Entrance = "/" + str.RandomString(6)
config.App.Key = str.Random(32)
config.HTTP.Entrance = "/" + str.Random(6)
encoded, err := yaml.Marshal(config)
if err != nil {

View File

@@ -8,6 +8,7 @@ import (
"strings"
"github.com/go-rat/chix"
"github.com/go-rat/utils/collect"
"github.com/hashicorp/go-version"
"github.com/shirou/gopsutil/disk"
"github.com/shirou/gopsutil/host"
@@ -20,7 +21,6 @@ import (
"github.com/TheTNB/panel/pkg/api"
"github.com/TheTNB/panel/pkg/db"
"github.com/TheTNB/panel/pkg/shell"
"github.com/TheTNB/panel/pkg/str"
"github.com/TheTNB/panel/pkg/tools"
"github.com/TheTNB/panel/pkg/types"
)
@@ -295,7 +295,7 @@ func (s *DashboardService) Update(w http.ResponseWriter, r *http.Request) {
return
}
download := str.FirstElement(panel.Downloads)
download := collect.First(panel.Downloads)
if download == nil {
Error(w, http.StatusInternalServerError, "获取下载链接失败")
return