Skip to content

Commit

Permalink
feat: Uniform state style
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu committed Dec 19, 2024
1 parent 07e4f34 commit d43a09e
Show file tree
Hide file tree
Showing 61 changed files with 311 additions and 487 deletions.
2 changes: 1 addition & 1 deletion agent/app/service/ftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func (f *FtpService) Sync() error {
}
for _, item := range listsInDB {
if _, ok := sameData[item.User]; !ok {
_ = ftpRepo.Update(item.ID, map[string]interface{}{"status": "deleted"})
_ = ftpRepo.Update(item.ID, map[string]interface{}{"status": constant.StatusDeleted})
}
}
return nil
Expand Down
1 change: 1 addition & 0 deletions agent/constant/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const (
StatusEnable = "Enable"
StatusDisable = "Disable"
StatusNone = "None"
StatusDeleted = "Deleted"

OrderDesc = "descending"
OrderAsc = "ascending"
Expand Down
7 changes: 0 additions & 7 deletions agent/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ func Init() {
migrations.InitImageRepo,
migrations.InitDefaultCA,
migrations.InitPHPExtensions,
migrations.UpdateWebsite,
migrations.UpdateWebsiteDomain,
migrations.UpdateApp,
migrations.AddTaskDB,
migrations.UpdateAppInstall,
migrations.UpdateSnapshot,
migrations.UpdateCronjob,
migrations.InitBaseDir,
})
if err := m.Migrate(); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion core/app/api/v2/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ func (b *BaseApi) MFABind(c *gin.Context) {
return
}

if err := settingService.Update("MFAStatus", "enable"); err != nil {
if err := settingService.Update("MFAStatus", constant.StatusEnable); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
Expand Down
8 changes: 4 additions & 4 deletions core/app/service/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (u *AuthService) Login(c *gin.Context, info dto.Login, entrance string) (*d
if err = settingRepo.Update("Language", info.Language); err != nil {
return nil, err
}
if mfa.Value == "enable" {
if mfa.Value == constant.StatusEnable {
return &dto.UserLoginInfo{Name: nameSetting.Value, MfaStatus: mfa.Value}, nil
}
return u.generateSession(c, info.Name, info.AuthMethod)
Expand Down Expand Up @@ -134,13 +134,13 @@ func (u *AuthService) generateSession(c *gin.Context, name, authMethod string) (
}
sessionUser, err := global.SESSION.Get(c)
if err != nil {
err := global.SESSION.Set(c, sessionUser, httpsSetting.Value == "enable", lifeTime)
err := global.SESSION.Set(c, sessionUser, httpsSetting.Value == constant.StatusEnable, lifeTime)
if err != nil {
return nil, err
}
return &dto.UserLoginInfo{Name: name}, nil
}
if err := global.SESSION.Set(c, sessionUser, httpsSetting.Value == "enable", lifeTime); err != nil {
if err := global.SESSION.Set(c, sessionUser, httpsSetting.Value == constant.StatusEnable, lifeTime); err != nil {
return nil, err
}

Expand All @@ -154,7 +154,7 @@ func (u *AuthService) LogOut(c *gin.Context) error {
}
sID, _ := c.Cookie(constant.SessionName)
if sID != "" {
c.SetCookie(constant.SessionName, sID, -1, "", "", httpsSetting.Value == "enable", true)
c.SetCookie(constant.SessionName, sID, -1, "", "", httpsSetting.Value == constant.StatusEnable, true)
err := global.SESSION.Delete(c)
if err != nil {
return err
Expand Down
6 changes: 3 additions & 3 deletions core/app/service/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ func (u *SettingService) UpdatePort(port uint) error {

func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error {
secretDir := path.Join(global.CONF.System.BaseDir, "1panel/secret")
if req.SSL == "disable" {
if err := settingRepo.Update("SSL", "disable"); err != nil {
if req.SSL == constant.StatusDisable {
if err := settingRepo.Update("SSL", constant.StatusDisable); err != nil {
return err
}
if err := settingRepo.Update("SSLType", "self"); err != nil {
Expand Down Expand Up @@ -275,7 +275,7 @@ func (u *SettingService) LoadFromCert() (*dto.SSLInfo, error) {
if err != nil {
return nil, err
}
if ssl.Value == "disable" {
if ssl.Value == constant.StatusDisable {
return &dto.SSLInfo{}, nil
}
sslType, err := settingRepo.Get(repo.WithByKey("SSLType"))
Expand Down
4 changes: 2 additions & 2 deletions core/app/service/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (u *UpgradeService) SearchUpgrade() (*dto.UpgradeInfo, error) {
if len(upgrade.NewVersion) != 0 {
itemVersion = upgrade.NewVersion
}
if (global.CONF.System.Mode == "dev" || DeveloperMode.Value == "enable") && len(upgrade.TestVersion) != 0 {
if (global.CONF.System.Mode == "dev" || DeveloperMode.Value == constant.StatusEnable) && len(upgrade.TestVersion) != 0 {
itemVersion = upgrade.TestVersion
}
if len(itemVersion) == 0 {
Expand Down Expand Up @@ -232,7 +232,7 @@ func (u *UpgradeService) loadVersionByMode(developer, currentVersion string) (st
betaVersionLatest := ""
latest = u.loadVersion(true, currentVersion, "stable")
current = u.loadVersion(false, currentVersion, "stable")
if developer == "enable" {
if developer == constant.StatusEnable {
betaVersionLatest = u.loadVersion(true, currentVersion, "beta")
}
if current != latest {
Expand Down
5 changes: 3 additions & 2 deletions core/cmd/server/cmd/listen-ip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"

"github.com/1Panel-dev/1Panel/core/constant"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -41,11 +42,11 @@ func updateBindInfo(protocol string) error {
if err != nil {
return err
}
ipv6 := "disable"
ipv6 := constant.StatusDisable
tcp := "tcp4"
address := "0.0.0.0"
if protocol == "ipv6" {
ipv6 = "enable"
ipv6 = constant.StatusEnable
tcp = "tcp6"
address = "::"
}
Expand Down
5 changes: 3 additions & 2 deletions core/cmd/server/cmd/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"fmt"

"github.com/1Panel-dev/1Panel/core/constant"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -33,7 +34,7 @@ var resetMFACmd = &cobra.Command{
return err
}

return setSettingByKey(db, "MFAStatus", "disable")
return setSettingByKey(db, "MFAStatus", constant.StatusDisable)
},
}
var resetSSLCmd = &cobra.Command{
Expand All @@ -49,7 +50,7 @@ var resetSSLCmd = &cobra.Command{
return err
}

return setSettingByKey(db, "SSL", "disable")
return setSettingByKey(db, "SSL", constant.StatusDisable)
},
}
var resetEntranceCmd = &cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion core/cmd/server/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"
"unicode"

"github.com/1Panel-dev/1Panel/core/constant"
"github.com/1Panel-dev/1Panel/core/global"
"github.com/1Panel-dev/1Panel/core/utils/cmd"
"github.com/1Panel-dev/1Panel/core/utils/common"
Expand Down Expand Up @@ -123,7 +124,7 @@ func password() {
return
}
complexSetting := getSettingByKey(db, "ComplexityVerification")
if complexSetting == "enable" {
if complexSetting == constant.StatusEnable {
if isValidPassword("newPassword") {
fmt.Println("\n错误:面板密码仅支持字母、数字、特殊字符(!@#$%*_,.?),长度 8-30 位!")
return
Expand Down
3 changes: 0 additions & 3 deletions core/constant/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ const (
OrderDesc = "descending"
OrderAsc = "ascending"

StatusEnable = "Enable"
StatusDisable = "Disable"

// backup
S3 = "S3"
OSS = "OSS"
Expand Down
34 changes: 18 additions & 16 deletions core/constant/status.go
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
package constant

const (
StatusSuccess = "success"
StatusFailed = "failed"
StatusSuccess = "Success"
StatusFailed = "Failed"

// node
StatusWaiting = "waiting"
StatusDownloading = "downloading"
StatusPacking = "packing"
StatusSending = "sending"
StatusStarting = "starting"
StatusHealthy = "healthy"
StatusUnhealthy = "unhealthy"
StatusUpgrading = "upgrading"
StatusRunning = "running"
StatusFree = "free"
StatusBound = "bound"
StatusExceptional = "exceptional"
StatusRetrying = "retrying"
StatusLost = "lost"
StatusWaiting = "Waiting"
StatusPacking = "Packing"
StatusSending = "Sending"
StatusStarting = "Starting"
StatusHealthy = "Healthy"
StatusUnhealthy = "Unhealthy"
StatusUpgrading = "Upgrading"
StatusRunning = "Running"
StatusFree = "Free"
StatusBound = "Bound"
StatusExceptional = "Exceptional"
StatusRetrying = "Retrying"
StatusLost = "Lost"

StatusEnable = "Enable"
StatusDisable = "Disable"
)
1 change: 1 addition & 0 deletions core/init/migration/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func Init() {
migrations.InitBackup,
migrations.InitGoogle,
migrations.AddTaskDB,
migrations.UpdateSettingStatus,
})
if err := m.Migrate(); err != nil {
global.LOG.Error(err)
Expand Down
27 changes: 20 additions & 7 deletions core/init/migration/migrations/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ var InitSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "Theme", Value: "light"}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "MenuTabs", Value: "disable"}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "MenuTabs", Value: constant.StatusDisable}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "PanelName", Value: "1Panel"}).Error; err != nil {
Expand All @@ -64,11 +64,11 @@ var InitSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "SSLID", Value: "0"}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "SSL", Value: "disable"}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "SSL", Value: constant.StatusDisable}).Error; err != nil {
return err
}

if err := tx.Create(&model.Setting{Key: "DeveloperMode", Value: "disable"}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "DeveloperMode", Value: constant.StatusDisable}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "ProxyType", Value: ""}).Error; err != nil {
Expand Down Expand Up @@ -111,10 +111,10 @@ var InitSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "ExpirationDays", Value: "0"}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "ComplexityVerification", Value: "enable"}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "ComplexityVerification", Value: constant.StatusEnable}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "MFAStatus", Value: "disable"}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "MFAStatus", Value: constant.StatusDisable}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "MFASecret", Value: ""}).Error; err != nil {
Expand All @@ -132,7 +132,7 @@ var InitSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "BindAddress", Value: "0.0.0.0"}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "Ipv6", Value: "disable"}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "Ipv6", Value: constant.StatusDisable}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "BindDomain", Value: ""}).Error; err != nil {
Expand Down Expand Up @@ -219,7 +219,7 @@ var InitTerminalSetting = &gormigrate.Migration{
if err := tx.Create(&model.Setting{Key: "FontSize", Value: "12"}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "CursorBlink", Value: "enable"}).Error; err != nil {
if err := tx.Create(&model.Setting{Key: "CursorBlink", Value: constant.StatusEnable}).Error; err != nil {
return err
}
if err := tx.Create(&model.Setting{Key: "CursorStyle", Value: "block"}).Error; err != nil {
Expand Down Expand Up @@ -270,3 +270,16 @@ var AddTaskDB = &gormigrate.Migration{
)
},
}

var UpdateSettingStatus = &gormigrate.Migration{
ID: "20241218-update-setting-status",
Migrate: func(tx *gorm.DB) error {
if err := tx.Model(model.Setting{}).Where("value = ?", "enable").Update("value", constant.StatusEnable).Error; err != nil {
return err
}
if err := tx.Model(model.Setting{}).Where("value = ?", "disable").Update("value", constant.StatusDisable).Error; err != nil {
return err
}
return nil
},
}
2 changes: 1 addition & 1 deletion core/middleware/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func SessionAuth() gin.HandlerFunc {
global.LOG.Errorf("create operation record failed, err: %v", err)
return
}
_ = global.SESSION.Set(c, psession, httpsSetting.Value == "enable", lifeTime)
_ = global.SESSION.Set(c, psession, httpsSetting.Value == constant.StatusEnable, lifeTime)
c.Next()
}
}
5 changes: 3 additions & 2 deletions core/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"path"

"github.com/1Panel-dev/1Panel/core/constant"
"github.com/1Panel-dev/1Panel/core/global"
"github.com/1Panel-dev/1Panel/core/i18n"
"github.com/1Panel-dev/1Panel/core/init/cron"
Expand Down Expand Up @@ -42,7 +43,7 @@ func Start() {
rootRouter := router.Routers()

tcpItem := "tcp4"
if global.CONF.System.Ipv6 == "enable" {
if global.CONF.System.Ipv6 == constant.StatusEnable {
tcpItem = "tcp"
global.CONF.System.BindAddress = fmt.Sprintf("[%s]", global.CONF.System.BindAddress)
}
Expand All @@ -57,7 +58,7 @@ func Start() {
type tcpKeepAliveListener struct {
*net.TCPListener
}
if global.CONF.System.SSL == "enable" {
if global.CONF.System.SSL == constant.StatusEnable {
certPath := path.Join(global.CONF.System.BaseDir, "1panel/secret/server.crt")
keyPath := path.Join(global.CONF.System.BaseDir, "1panel/secret/server.key")
certificate, err := os.ReadFile(certPath)
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/api/interface/host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ export namespace Host {

export interface FirewallBase {
name: string;
status: string;
isExist: boolean;
isActive: boolean;
version: string;
pingStatus: string;
}
Expand Down Expand Up @@ -148,7 +149,7 @@ export namespace Host {

export interface SSHInfo {
autoStart: boolean;
status: string;
isActive: boolean;
message: string;
port: string;
listenAddress: string;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/app-status/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<div class="flex w-full flex-col gap-4 md:flex-row">
<div class="flex flex-wrap gap-4">
<el-tag effect="dark" type="success">{{ data.app }}</el-tag>
<Status :key="refresh" :status="data.status"></Status>
<Status class="mt-0.5" :key="refresh" :status="data.status"></Status>
<el-tag>{{ $t('app.version') }}{{ data.version }}</el-tag>
</div>

Expand Down
Loading

0 comments on commit d43a09e

Please sign in to comment.