Skip to content

Commit

Permalink
Apply multilingual support
Browse files Browse the repository at this point in the history
  • Loading branch information
LinkLeong committed Jan 26, 2022
1 parent 26e5b18 commit d060968
Show file tree
Hide file tree
Showing 15 changed files with 3,550 additions and 1,421 deletions.
2 changes: 1 addition & 1 deletion UI
2 changes: 1 addition & 1 deletion route/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func installSyncthing(appId string) {
m := model.CustomizationPostData{}
var dockerImage string
var dockerImageVersion string
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system")
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system", "us_en")
dockerImage = appInfo.Image
dockerImageVersion = appInfo.ImageVersion

Expand Down
6 changes: 4 additions & 2 deletions route/v1/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ func AppList(c *gin.Context) {
t := c.DefaultQuery("type", "rank")
categoryId := c.DefaultQuery("category_id", "0")
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++ {
// ct, _ := service.MyService.Docker().DockerListByImage(recommend[i].Image, recommend[i].ImageVersion)
// if ct != nil {
Expand Down Expand Up @@ -137,7 +138,8 @@ func AppUsageList(c *gin.Context) {
func AppInfo(c *gin.Context) {

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" {
for i := 0; i < len(info.Ports); i++ {
if p, _ := strconv.Atoi(info.Ports[i].ContainerPort); port2.IsPortAvailable(p, info.Ports[i].Protocol) {
Expand Down
2 changes: 1 addition & 1 deletion route/v1/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func GetDiskList(c *gin.Context) {
continue
}

if list[i].Tran == "sata" {
if list[i].Tran == "sata" || list[i].Tran == "nvme" {
temp := service.MyService.Disk().SmartCTL(list[i].Path)
if reflect.DeepEqual(temp, model.SmartctlA{}) {
continue
Expand Down
3 changes: 2 additions & 1 deletion route/v1/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func SpeedPush(c *gin.Context) {
// @Router /app/install/{id} [post]
func InstallApp(c *gin.Context) {
appId := c.Param("id")
language := c.GetHeader("Language")
var appInfo model.ServerAppList
m := model.CustomizationPostData{}
c.BindJSON(&m)
Expand Down Expand Up @@ -174,7 +175,7 @@ func InstallApp(c *gin.Context) {
dockerImageVersion = "latest"
}
if m.Origin != "custom" {
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "")
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "", language)

} else {

Expand Down
2 changes: 1 addition & 1 deletion route/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ func Info(c *gin.Context) {
findSystem += 1
continue
}
if list[i].Tran == "sata" {
if list[i].Tran == "sata" || list[i].Tran == "nvme" {
temp := service.MyService.Disk().SmartCTL(list[i].Path)
if reflect.DeepEqual(temp, model.SmartctlA{}) {
continue
Expand Down
26 changes: 21 additions & 5 deletions route/v1/zerotier.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ package v1

import (
json2 "encoding/json"
"net/http"

"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
"github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin"
"net/http"
)

// @Summary 登录zerotier获取token
Expand Down Expand Up @@ -432,11 +433,17 @@ func ZeroTierDeleteNetwork(c *gin.Context) {
// @Router /zerotier/join/{id} [post]
func ZeroTierJoinNetwork(c *gin.Context) {
networkId := c.Param("id")
service.MyService.ZeroTier().ZeroTierJoinNetwork(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)})
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)})
}

Expand All @@ -450,10 +457,19 @@ func ZeroTierJoinNetwork(c *gin.Context) {
// @Router /zerotier/leave/{id} [post]
func ZeroTierLeaveNetwork(c *gin.Context) {
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)})
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)})
}
14 changes: 7 additions & 7 deletions service/casa.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
)

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
GetTaskList(size int) []model2.TaskDBModel
GetServerAppInfo(id, t string) model.ServerAppList
GetServerAppInfo(id, t string, language string) model.ServerAppList
ShareAppFile(body []byte) string
}

Expand Down Expand Up @@ -45,9 +45,9 @@ func (o *casaService) GetTaskList(size int) []model2.TaskDBModel {
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 {
res, ok := result.(string)
Expand All @@ -63,7 +63,7 @@ func (o *casaService) GetServerList(index, size, tp, categoryId, key string) (re

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.recommend").String()), &recommend)
Expand All @@ -88,12 +88,12 @@ func (o *casaService) GetServerCategoryList() []model.ServerCategoryList {

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["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{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)
Expand Down
22 changes: 16 additions & 6 deletions service/zerotier.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,20 @@ import (
"bytes"
"errors"
"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"
"math/rand"
"net/http"
"strconv"
"strings"
"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 {
Expand All @@ -33,6 +35,7 @@ type ZeroTierService interface {
DeleteMember(token string, id, mId string) interface{}
DeleteNetwork(token, id string) interface{}
GetJoinNetworks() string
NetworkIdFilter(letter rune) bool
}
type zerotierStruct struct {
}
Expand Down Expand Up @@ -333,6 +336,13 @@ func (c *zerotierStruct) GetJoinNetworks() string {
return json
}

func (c *zerotierStruct) NetworkIdFilter(letter rune) bool {
if unicode.IsNumber(letter) || unicode.IsLetter(letter) {
return true
} else {
return false
}
}
func NewZeroTierService() ZeroTierService {
//初始化client
client = http.Client{Timeout: 30 * time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error {
Expand Down
4 changes: 2 additions & 2 deletions types/system.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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>"
292 changes: 135 additions & 157 deletions web/js/2.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions web/js/3.js

Large diffs are not rendered by default.

Loading

0 comments on commit d060968

Please sign in to comment.