Skip to content

Commit

Permalink
feat: 同步前端更改
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 29, 2023
1 parent 462b2f9 commit f757862
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 21 deletions.
16 changes: 9 additions & 7 deletions app/http/controllers/info_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,14 +156,16 @@ func (c *InfoController) CountInfo(ctx http.Context) http.Response {
if status == "active" {
raw := tools.Exec(`echo "\l" | su - postgres -c "psql"`)
databases := strings.Split(raw, "\n")
databases = databases[3 : len(databases)-1]
for _, db := range databases {
parts := strings.Split(db, "|")
if len(parts) != 9 || len(strings.TrimSpace(parts[0])) == 0 || strings.TrimSpace(parts[0]) == "template0" || strings.TrimSpace(parts[0]) == "template1" || strings.TrimSpace(parts[0]) == "postgres" {
continue
}
if len(databases) >= 4 {
databases = databases[3 : len(databases)-1]
for _, db := range databases {
parts := strings.Split(db, "|")
if len(parts) != 9 || len(strings.TrimSpace(parts[0])) == 0 || strings.TrimSpace(parts[0]) == "template0" || strings.TrimSpace(parts[0]) == "template1" || strings.TrimSpace(parts[0]) == "postgres" {
continue
}

databaseCount++
databaseCount++
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,23 @@ func (c *Postgresql15Controller) DatabaseList(ctx http.Context) http.Response {
return controllers.Error(ctx, http.StatusInternalServerError, "PostgreSQL 已停止运行")
}

raw := tools.Exec(`echo "\l" | su - postgres -c "psql"`)
databases := strings.Split(raw, "\n")
databases = databases[3 : len(databases)-1]

type database struct {
Name string `json:"name"`
Owner string `json:"owner"`
Encoding string `json:"encoding"`
}

raw := tools.Exec(`echo "\l" | su - postgres -c "psql"`)
databases := strings.Split(raw, "\n")
if len(databases) >= 4 {
databases = databases[3 : len(databases)-1]
} else {
return controllers.Success(ctx, http.Json{
"total": 0,
"items": []database{},
})
}

var databaseList []database
for _, db := range databases {
parts := strings.Split(db, "|")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,23 @@ func (c *Postgresql16Controller) DatabaseList(ctx http.Context) http.Response {
return controllers.Error(ctx, http.StatusInternalServerError, "PostgreSQL 已停止运行")
}

raw := tools.Exec(`echo "\l" | su - postgres -c "psql"`)
databases := strings.Split(raw, "\n")
databases = databases[3 : len(databases)-1]

type database struct {
Name string `json:"name"`
Owner string `json:"owner"`
Encoding string `json:"encoding"`
}

raw := tools.Exec(`echo "\l" | su - postgres -c "psql"`)
databases := strings.Split(raw, "\n")
if len(databases) >= 4 {
databases = databases[3 : len(databases)-1]
} else {
return controllers.Success(ctx, http.Json{
"total": 0,
"items": []database{},
})
}

var databaseList []database
for _, db := range databases {
parts := strings.Split(db, "|")
Expand Down
25 changes: 19 additions & 6 deletions app/http/controllers/plugins/toolbox/toolbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package toolbox

import (
"regexp"
"strconv"
"strings"

"github.com/goravel/framework/contracts/http"
Expand Down Expand Up @@ -69,13 +68,14 @@ func (c *ToolBoxController) GetSWAP(ctx http.Context) http.Response {
return check
}

var total, size, used, free string
var total, used, free string
var size int64
if tools.Exists("/www/swap") {
s, _ := tools.FileSize("/www/swap")
size = strconv.Itoa(int(s / 1024 / 1024))
size = s / 1024 / 1024
total = tools.FormatBytes(float64(s))
} else {
size = "0.00 B"
size = 0
total = "0.00 B"
}

Expand Down Expand Up @@ -142,12 +142,25 @@ func (c *ToolBoxController) GetTimezone(ctx http.Context) http.Response {
return controllers.Error(ctx, http.StatusUnprocessableEntity, "找不到时区信息")
}

type zone struct {
Label string `json:"label"`
Value string `json:"value"`
}

zonesRaw := tools.Exec("LC_ALL=C timedatectl list-timezones")
zones := strings.Split(zonesRaw, "\n")

var zonesList []zone
for _, z := range zones {
zonesList = append(zonesList, zone{
Label: z,
Value: z,
})
}

return controllers.Success(ctx, http.Json{
"zone": match[1],
"zones": zones,
"timezone": match[1],
"timezones": zonesList,
})
}

Expand Down

0 comments on commit f757862

Please sign in to comment.