fix: fix issue with appstore (#8554)

This commit is contained in:
ChengPlay 2025-05-06 18:33:07 +08:00 committed by GitHub
parent bdeff3d281
commit 3c81aced62
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 35 additions and 14 deletions

View file

@ -170,7 +170,7 @@ func (u *BackupService) Delete(name string) error {
if backup.Type == constant.Local { if backup.Type == constant.Local {
return buserr.New("ErrBackupLocal") return buserr.New("ErrBackupLocal")
} }
if _, err := proxy_local.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%s", name), http.MethodGet, nil); err != nil { if _, err := proxy_local.NewLocalClient(fmt.Sprintf("/api/v2/backups/check/%s", name), http.MethodGet, nil, nil); err != nil {
global.LOG.Errorf("check used of local cronjob failed, err: %v", err) global.LOG.Errorf("check used of local cronjob failed, err: %v", err)
return buserr.New("ErrBackupInUsed") return buserr.New("ErrBackupInUsed")
} }

View file

@ -110,7 +110,7 @@ func (u *GroupService) Delete(id uint) error {
err = xpack.UpdateGroup("node", id, defaultGroup.ID) err = xpack.UpdateGroup("node", id, defaultGroup.ID)
case "website": case "website":
bodyItem := []byte(fmt.Sprintf(`{"Group":%v, "NewGroup":%v}`, id, defaultGroup.ID)) bodyItem := []byte(fmt.Sprintf(`{"Group":%v, "NewGroup":%v}`, id, defaultGroup.ID))
if _, err := proxy_local.NewLocalClient("/api/v2/websites/group/change", http.MethodPost, bytes.NewReader(bodyItem)); err != nil { if _, err := proxy_local.NewLocalClient("/api/v2/websites/group/change", http.MethodPost, bytes.NewReader(bodyItem), nil); err != nil {
return err return err
} }
if err := xpack.UpdateGroup("node", id, defaultGroup.ID); err != nil { if err := xpack.UpdateGroup("node", id, defaultGroup.ID); err != nil {

View file

@ -320,7 +320,7 @@ func (u *SettingService) UpdateSSL(c *gin.Context, req dto.SSLUpdate) error {
if err != nil { if err != nil {
return err return err
} }
res, err := proxy_local.NewLocalClient("/api/v2/websites/ca/obtain", http.MethodPost, bytes.NewReader(jsonData)) res, err := proxy_local.NewLocalClient("/api/v2/websites/ca/obtain", http.MethodPost, bytes.NewReader(jsonData), nil)
if err != nil { if err != nil {
return err return err
} }

View file

@ -2,6 +2,7 @@ package i18n
import ( import (
"embed" "embed"
"github.com/1Panel-dev/1Panel/core/app/repo"
"strings" "strings"
"github.com/1Panel-dev/1Panel/core/global" "github.com/1Panel-dev/1Panel/core/global"
@ -113,7 +114,7 @@ func UseI18n() gin.HandlerFunc {
return func(context *gin.Context) { return func(context *gin.Context) {
lang := context.GetHeader("Accept-Language") lang := context.GetHeader("Accept-Language")
if lang == "" { if lang == "" {
lang = "en" lang = GetLanguageFromDB()
} }
global.I18n = i18n.NewLocalizer(bundle, lang) global.I18n = i18n.NewLocalizer(bundle, lang)
} }
@ -132,7 +133,8 @@ func Init() {
_, _ = bundle.LoadMessageFileFS(fs, "lang/ru.yaml") _, _ = bundle.LoadMessageFileFS(fs, "lang/ru.yaml")
_, _ = bundle.LoadMessageFileFS(fs, "lang/ms.yaml") _, _ = bundle.LoadMessageFileFS(fs, "lang/ms.yaml")
_, _ = bundle.LoadMessageFileFS(fs, "lang/ko.yaml") _, _ = bundle.LoadMessageFileFS(fs, "lang/ko.yaml")
global.I18n = i18n.NewLocalizer(bundle, "en") lang := GetLanguageFromDB()
global.I18n = i18n.NewLocalizer(bundle, lang)
} }
func UseI18nForCmd(lang string) { func UseI18nForCmd(lang string) {
@ -176,3 +178,14 @@ func GetMsgWithMapForCmd(key string, maps map[string]interface{}) string {
return content return content
} }
} }
func GetLanguageFromDB() string {
if global.DB == nil {
return "en"
}
lang, _ := repo.NewISettingRepo().GetValueByKey("Language")
if lang == "" {
return "en"
}
return lang
}

View file

@ -1,4 +1,4 @@
package lang package geo
import ( import (
"fmt" "fmt"

View file

@ -5,6 +5,9 @@ import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"github.com/1Panel-dev/1Panel/core/init/db" "github.com/1Panel-dev/1Panel/core/init/db"
"github.com/1Panel-dev/1Panel/core/init/geo"
"github.com/1Panel-dev/1Panel/core/init/log"
"github.com/1Panel-dev/1Panel/core/init/migration"
"net" "net"
"net/http" "net/http"
"os" "os"
@ -15,9 +18,6 @@ import (
"github.com/1Panel-dev/1Panel/core/i18n" "github.com/1Panel-dev/1Panel/core/i18n"
"github.com/1Panel-dev/1Panel/core/init/cron" "github.com/1Panel-dev/1Panel/core/init/cron"
"github.com/1Panel-dev/1Panel/core/init/hook" "github.com/1Panel-dev/1Panel/core/init/hook"
"github.com/1Panel-dev/1Panel/core/init/lang"
"github.com/1Panel-dev/1Panel/core/init/log"
"github.com/1Panel-dev/1Panel/core/init/migration"
"github.com/1Panel-dev/1Panel/core/init/router" "github.com/1Panel-dev/1Panel/core/init/router"
"github.com/1Panel-dev/1Panel/core/init/session" "github.com/1Panel-dev/1Panel/core/init/session"
"github.com/1Panel-dev/1Panel/core/init/session/psession" "github.com/1Panel-dev/1Panel/core/init/session/psession"
@ -29,12 +29,12 @@ import (
func Start() { func Start() {
viper.Init() viper.Init()
db.Init()
i18n.Init()
log.Init() log.Init()
db.Init()
migration.Init() migration.Init()
i18n.Init()
validator.Init() validator.Init()
lang.Init() geo.Init()
gob.Register(psession.SessionUser{}) gob.Register(psession.SessionUser{})
cron.Init() cron.Init()
session.Init() session.Init()

View file

@ -5,6 +5,7 @@ import (
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
"github.com/gin-gonic/gin"
"io" "io"
"net" "net"
"net/http" "net/http"
@ -16,7 +17,7 @@ import (
"github.com/1Panel-dev/1Panel/core/i18n" "github.com/1Panel-dev/1Panel/core/i18n"
) )
func NewLocalClient(reqUrl, reqMethod string, body io.Reader) (interface{}, error) { func NewLocalClient(reqUrl, reqMethod string, body io.Reader, ctx *gin.Context) (interface{}, error) {
sockPath := "/etc/1panel/agent.sock" sockPath := "/etc/1panel/agent.sock"
if _, err := os.Stat(sockPath); err != nil { if _, err := os.Stat(sockPath); err != nil {
return nil, fmt.Errorf("no such agent.sock find in localhost, err: %v", err) return nil, fmt.Errorf("no such agent.sock find in localhost, err: %v", err)
@ -47,6 +48,13 @@ func NewLocalClient(reqUrl, reqMethod string, body io.Reader) (interface{}, erro
if err != nil { if err != nil {
return nil, fmt.Errorf("creating request failed, err: %v", err) return nil, fmt.Errorf("creating request failed, err: %v", err)
} }
if ctx != nil {
for key, values := range ctx.Request.Header {
for _, value := range values {
req.Header.Add(key, value)
}
}
}
resp, err := client.Do(req) resp, err := client.Do(req)
if err != nil { if err != nil {

View file

@ -10,7 +10,7 @@
</el-col> </el-col>
<el-col :span="12"> <el-col :span="12">
<span>{{ app.name }}</span> <span>{{ app.name }}</span>
<div class="app-margin"> <div>
<el-tag v-if="app.version != ''">{{ app.version }}</el-tag> <el-tag v-if="app.version != ''">{{ app.version }}</el-tag>
<el-tag v-else>{{ $t('commons.table.all') + $t('app.version') }}</el-tag> <el-tag v-else>{{ $t('commons.table.all') + $t('app.version') }}</el-tag>
</div> </div>