1
0
mirror of https://github.com/IceWhaleTech/CasaOS.git synced 2025-07-06 23:37:26 +02:00

Apply multilingual support

This commit is contained in:
link
2022-01-26 18:50:34 +08:00
parent 26e5b18a5d
commit d060968b7a
15 changed files with 2346 additions and 217 deletions

2
UI

Submodule UI updated: d457b64e26...a6074812f4

View File

@ -35,7 +35,7 @@ func installSyncthing(appId string) {
m := model.CustomizationPostData{} m := model.CustomizationPostData{}
var dockerImage string var dockerImage string
var dockerImageVersion string var dockerImageVersion string
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system") appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system", "us_en")
dockerImage = appInfo.Image dockerImage = appInfo.Image
dockerImageVersion = appInfo.ImageVersion dockerImageVersion = appInfo.ImageVersion

View File

@ -35,7 +35,8 @@ func AppList(c *gin.Context) {
t := c.DefaultQuery("type", "rank") t := c.DefaultQuery("type", "rank")
categoryId := c.DefaultQuery("category_id", "0") categoryId := c.DefaultQuery("category_id", "0")
key := c.DefaultQuery("key", "") key := c.DefaultQuery("key", "")
recommend, list, community := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key) language := c.GetHeader("Language")
recommend, list, community := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key, language)
// for i := 0; i < len(recommend); i++ { // for i := 0; i < len(recommend); i++ {
// ct, _ := service.MyService.Docker().DockerListByImage(recommend[i].Image, recommend[i].ImageVersion) // ct, _ := service.MyService.Docker().DockerListByImage(recommend[i].Image, recommend[i].ImageVersion)
// if ct != nil { // if ct != nil {
@ -137,7 +138,8 @@ func AppUsageList(c *gin.Context) {
func AppInfo(c *gin.Context) { func AppInfo(c *gin.Context) {
id := c.Param("id") id := c.Param("id")
info := service.MyService.OAPI().GetServerAppInfo(id, "") language := c.GetHeader("Language")
info := service.MyService.OAPI().GetServerAppInfo(id, "", language)
if info.NetworkModel != "host" { if info.NetworkModel != "host" {
for i := 0; i < len(info.Ports); i++ { for i := 0; i < len(info.Ports); i++ {
if p, _ := strconv.Atoi(info.Ports[i].ContainerPort); port2.IsPortAvailable(p, info.Ports[i].Protocol) { if p, _ := strconv.Atoi(info.Ports[i].ContainerPort); port2.IsPortAvailable(p, info.Ports[i].Protocol) {

View File

@ -82,7 +82,7 @@ func GetDiskList(c *gin.Context) {
continue continue
} }
if list[i].Tran == "sata" { if list[i].Tran == "sata" || list[i].Tran == "nvme" {
temp := service.MyService.Disk().SmartCTL(list[i].Path) temp := service.MyService.Disk().SmartCTL(list[i].Path)
if reflect.DeepEqual(temp, model.SmartctlA{}) { if reflect.DeepEqual(temp, model.SmartctlA{}) {
continue continue

View File

@ -145,6 +145,7 @@ func SpeedPush(c *gin.Context) {
// @Router /app/install/{id} [post] // @Router /app/install/{id} [post]
func InstallApp(c *gin.Context) { func InstallApp(c *gin.Context) {
appId := c.Param("id") appId := c.Param("id")
language := c.GetHeader("Language")
var appInfo model.ServerAppList var appInfo model.ServerAppList
m := model.CustomizationPostData{} m := model.CustomizationPostData{}
c.BindJSON(&m) c.BindJSON(&m)
@ -174,7 +175,7 @@ func InstallApp(c *gin.Context) {
dockerImageVersion = "latest" dockerImageVersion = "latest"
} }
if m.Origin != "custom" { if m.Origin != "custom" {
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "") appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "", language)
} else { } else {

View File

@ -286,7 +286,7 @@ func Info(c *gin.Context) {
findSystem += 1 findSystem += 1
continue continue
} }
if list[i].Tran == "sata" { if list[i].Tran == "sata" || list[i].Tran == "nvme" {
temp := service.MyService.Disk().SmartCTL(list[i].Path) temp := service.MyService.Disk().SmartCTL(list[i].Path)
if reflect.DeepEqual(temp, model.SmartctlA{}) { if reflect.DeepEqual(temp, model.SmartctlA{}) {
continue continue

View File

@ -2,12 +2,13 @@ package v1
import ( import (
json2 "encoding/json" json2 "encoding/json"
"net/http"
"github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config" "github.com/IceWhaleTech/CasaOS/pkg/config"
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err" oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
"github.com/IceWhaleTech/CasaOS/service" "github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"net/http"
) )
// @Summary 登录zerotier获取token // @Summary 登录zerotier获取token
@ -432,11 +433,17 @@ func ZeroTierDeleteNetwork(c *gin.Context) {
// @Router /zerotier/join/{id} [post] // @Router /zerotier/join/{id} [post]
func ZeroTierJoinNetwork(c *gin.Context) { func ZeroTierJoinNetwork(c *gin.Context) {
networkId := c.Param("id") networkId := c.Param("id")
service.MyService.ZeroTier().ZeroTierJoinNetwork(networkId) if len(networkId) != 16 {
if len(networkId) == 0 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return return
} }
for _, v := range networkId {
if !service.MyService.ZeroTier().NetworkIdFilter(v) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return
}
}
service.MyService.ZeroTier().ZeroTierJoinNetwork(networkId)
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
} }
@ -450,10 +457,19 @@ func ZeroTierJoinNetwork(c *gin.Context) {
// @Router /zerotier/leave/{id} [post] // @Router /zerotier/leave/{id} [post]
func ZeroTierLeaveNetwork(c *gin.Context) { func ZeroTierLeaveNetwork(c *gin.Context) {
networkId := c.Param("id") networkId := c.Param("id")
service.MyService.ZeroTier().ZeroTierLeaveNetwork(networkId)
if len(networkId) == 0 { if len(networkId) != 16 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return return
} }
for _, v := range networkId {
if !service.MyService.ZeroTier().NetworkIdFilter(v) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return
}
}
service.MyService.ZeroTier().ZeroTierLeaveNetwork(networkId)
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)}) c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
} }

View File

@ -13,10 +13,10 @@ import (
) )
type CasaService interface { type CasaService interface {
GetServerList(index, size, tp, categoryId, key string) (recommend, list, community []model.ServerAppList) GetServerList(index, size, tp, categoryId, key, language string) (recommend, list, community []model.ServerAppList)
GetServerCategoryList() []model.ServerCategoryList GetServerCategoryList() []model.ServerCategoryList
GetTaskList(size int) []model2.TaskDBModel GetTaskList(size int) []model2.TaskDBModel
GetServerAppInfo(id, t string) model.ServerAppList GetServerAppInfo(id, t string, language string) model.ServerAppList
ShareAppFile(body []byte) string ShareAppFile(body []byte) string
} }
@ -45,9 +45,9 @@ func (o *casaService) GetTaskList(size int) []model2.TaskDBModel {
return list return list
} }
func (o *casaService) GetServerList(index, size, tp, categoryId, key string) (recommend, list, community []model.ServerAppList) { func (o *casaService) GetServerList(index, size, tp, categoryId, key, language string) (recommend, list, community []model.ServerAppList) {
keyName := fmt.Sprintf("list_%s_%s_%s_%s", index, size, tp, categoryId) keyName := fmt.Sprintf("list_%s_%s_%s_%s_%s", index, size, tp, categoryId, language)
if result, ok := Cache.Get(keyName); ok { if result, ok := Cache.Get(keyName); ok {
res, ok := result.(string) res, ok := result.(string)
@ -63,7 +63,7 @@ func (o *casaService) GetServerList(index, size, tp, categoryId, key string) (re
head["Authorization"] = GetToken() head["Authorization"] = GetToken()
listS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/newlist?index="+index+"&size="+size+"&rank="+tp+"&category_id="+categoryId+"&key="+key, head) listS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/newlist?index="+index+"&size="+size+"&rank="+tp+"&category_id="+categoryId+"&key="+key+"&language="+language, head)
json2.Unmarshal([]byte(gjson.Get(listS, "data.list").String()), &list) json2.Unmarshal([]byte(gjson.Get(listS, "data.list").String()), &list)
json2.Unmarshal([]byte(gjson.Get(listS, "data.recommend").String()), &recommend) json2.Unmarshal([]byte(gjson.Get(listS, "data.recommend").String()), &recommend)
@ -88,12 +88,12 @@ func (o *casaService) GetServerCategoryList() []model.ServerCategoryList {
return list return list
} }
func (o *casaService) GetServerAppInfo(id, t string) model.ServerAppList { func (o *casaService) GetServerAppInfo(id, t string, language string) model.ServerAppList {
head := make(map[string]string) head := make(map[string]string)
head["Authorization"] = GetToken() head["Authorization"] = GetToken()
infoS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/info/"+id+"?t="+t, head) infoS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/info/"+id+"?t="+t+"&language="+language, head)
info := model.ServerAppList{} info := model.ServerAppList{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info) json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)

View File

@ -4,18 +4,20 @@ import (
"bytes" "bytes"
"errors" "errors"
"fmt" "fmt"
"github.com/IceWhaleTech/CasaOS/pkg/config"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
"github.com/IceWhaleTech/CasaOS/pkg/zerotier"
"github.com/PuerkitoBio/goquery"
"github.com/tidwall/gjson"
"io/ioutil" "io/ioutil"
"math/rand" "math/rand"
"net/http" "net/http"
"strconv" "strconv"
"strings" "strings"
"time" "time"
"unicode"
"github.com/IceWhaleTech/CasaOS/pkg/config"
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
"github.com/IceWhaleTech/CasaOS/pkg/zerotier"
"github.com/PuerkitoBio/goquery"
"github.com/tidwall/gjson"
) )
type ZeroTierService interface { type ZeroTierService interface {
@ -33,6 +35,7 @@ type ZeroTierService interface {
DeleteMember(token string, id, mId string) interface{} DeleteMember(token string, id, mId string) interface{}
DeleteNetwork(token, id string) interface{} DeleteNetwork(token, id string) interface{}
GetJoinNetworks() string GetJoinNetworks() string
NetworkIdFilter(letter rune) bool
} }
type zerotierStruct struct { type zerotierStruct struct {
} }
@ -333,6 +336,13 @@ func (c *zerotierStruct) GetJoinNetworks() string {
return json return json
} }
func (c *zerotierStruct) NetworkIdFilter(letter rune) bool {
if unicode.IsNumber(letter) || unicode.IsLetter(letter) {
return true
} else {
return false
}
}
func NewZeroTierService() ZeroTierService { func NewZeroTierService() ZeroTierService {
//初始化client //初始化client
client = http.Client{Timeout: 30 * time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error { client = http.Client{Timeout: 30 * time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error {

View File

@ -1,5 +1,5 @@
package types package types
const CURRENTVERSION = "0.2.6" const CURRENTVERSION = "0.2.7"
const BODY = "<li>Fix a disk that cannot be formatted under certain circumstances</li><li>Add a bug report panel.</li>" const BODY = "<li>Apply multilingual support</li><li>Fix a security vulnerability</li>"

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long