Skip to content

Commit d060968

Browse files
committed
Apply multilingual support
1 parent 26e5b18 commit d060968

File tree

15 files changed

+3550
-1421
lines changed

15 files changed

+3550
-1421
lines changed

Diff for: route/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func installSyncthing(appId string) {
3535
m := model.CustomizationPostData{}
3636
var dockerImage string
3737
var dockerImageVersion string
38-
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system")
38+
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "system", "us_en")
3939
dockerImage = appInfo.Image
4040
dockerImageVersion = appInfo.ImageVersion
4141

Diff for: route/v1/app.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ func AppList(c *gin.Context) {
3535
t := c.DefaultQuery("type", "rank")
3636
categoryId := c.DefaultQuery("category_id", "0")
3737
key := c.DefaultQuery("key", "")
38-
recommend, list, community := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key)
38+
language := c.GetHeader("Language")
39+
recommend, list, community := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key, language)
3940
// for i := 0; i < len(recommend); i++ {
4041
// ct, _ := service.MyService.Docker().DockerListByImage(recommend[i].Image, recommend[i].ImageVersion)
4142
// if ct != nil {
@@ -137,7 +138,8 @@ func AppUsageList(c *gin.Context) {
137138
func AppInfo(c *gin.Context) {
138139

139140
id := c.Param("id")
140-
info := service.MyService.OAPI().GetServerAppInfo(id, "")
141+
language := c.GetHeader("Language")
142+
info := service.MyService.OAPI().GetServerAppInfo(id, "", language)
141143
if info.NetworkModel != "host" {
142144
for i := 0; i < len(info.Ports); i++ {
143145
if p, _ := strconv.Atoi(info.Ports[i].ContainerPort); port2.IsPortAvailable(p, info.Ports[i].Protocol) {

Diff for: route/v1/disk.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func GetDiskList(c *gin.Context) {
8282
continue
8383
}
8484

85-
if list[i].Tran == "sata" {
85+
if list[i].Tran == "sata" || list[i].Tran == "nvme" {
8686
temp := service.MyService.Disk().SmartCTL(list[i].Path)
8787
if reflect.DeepEqual(temp, model.SmartctlA{}) {
8888
continue

Diff for: route/v1/docker.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ func SpeedPush(c *gin.Context) {
145145
// @Router /app/install/{id} [post]
146146
func InstallApp(c *gin.Context) {
147147
appId := c.Param("id")
148+
language := c.GetHeader("Language")
148149
var appInfo model.ServerAppList
149150
m := model.CustomizationPostData{}
150151
c.BindJSON(&m)
@@ -174,7 +175,7 @@ func InstallApp(c *gin.Context) {
174175
dockerImageVersion = "latest"
175176
}
176177
if m.Origin != "custom" {
177-
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "")
178+
appInfo = service.MyService.OAPI().GetServerAppInfo(appId, "", language)
178179

179180
} else {
180181

Diff for: route/v1/system.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ func Info(c *gin.Context) {
286286
findSystem += 1
287287
continue
288288
}
289-
if list[i].Tran == "sata" {
289+
if list[i].Tran == "sata" || list[i].Tran == "nvme" {
290290
temp := service.MyService.Disk().SmartCTL(list[i].Path)
291291
if reflect.DeepEqual(temp, model.SmartctlA{}) {
292292
continue

Diff for: route/v1/zerotier.go

+21-5
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ package v1
22

33
import (
44
json2 "encoding/json"
5+
"net/http"
6+
57
"github.com/IceWhaleTech/CasaOS/model"
68
"github.com/IceWhaleTech/CasaOS/pkg/config"
79
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
810
"github.com/IceWhaleTech/CasaOS/service"
911
"github.com/gin-gonic/gin"
10-
"net/http"
1112
)
1213

1314
// @Summary 登录zerotier获取token
@@ -432,11 +433,17 @@ func ZeroTierDeleteNetwork(c *gin.Context) {
432433
// @Router /zerotier/join/{id} [post]
433434
func ZeroTierJoinNetwork(c *gin.Context) {
434435
networkId := c.Param("id")
435-
service.MyService.ZeroTier().ZeroTierJoinNetwork(networkId)
436-
if len(networkId) == 0 {
436+
if len(networkId) != 16 {
437437
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
438438
return
439439
}
440+
for _, v := range networkId {
441+
if !service.MyService.ZeroTier().NetworkIdFilter(v) {
442+
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
443+
return
444+
}
445+
}
446+
service.MyService.ZeroTier().ZeroTierJoinNetwork(networkId)
440447
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
441448
}
442449

@@ -450,10 +457,19 @@ func ZeroTierJoinNetwork(c *gin.Context) {
450457
// @Router /zerotier/leave/{id} [post]
451458
func ZeroTierLeaveNetwork(c *gin.Context) {
452459
networkId := c.Param("id")
453-
service.MyService.ZeroTier().ZeroTierLeaveNetwork(networkId)
454-
if len(networkId) == 0 {
460+
461+
if len(networkId) != 16 {
455462
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
456463
return
457464
}
465+
466+
for _, v := range networkId {
467+
if !service.MyService.ZeroTier().NetworkIdFilter(v) {
468+
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
469+
return
470+
}
471+
}
472+
service.MyService.ZeroTier().ZeroTierLeaveNetwork(networkId)
473+
458474
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
459475
}

Diff for: service/casa.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
)
1414

1515
type CasaService interface {
16-
GetServerList(index, size, tp, categoryId, key string) (recommend, list, community []model.ServerAppList)
16+
GetServerList(index, size, tp, categoryId, key, language string) (recommend, list, community []model.ServerAppList)
1717
GetServerCategoryList() []model.ServerCategoryList
1818
GetTaskList(size int) []model2.TaskDBModel
19-
GetServerAppInfo(id, t string) model.ServerAppList
19+
GetServerAppInfo(id, t string, language string) model.ServerAppList
2020
ShareAppFile(body []byte) string
2121
}
2222

@@ -45,9 +45,9 @@ func (o *casaService) GetTaskList(size int) []model2.TaskDBModel {
4545
return list
4646
}
4747

48-
func (o *casaService) GetServerList(index, size, tp, categoryId, key string) (recommend, list, community []model.ServerAppList) {
48+
func (o *casaService) GetServerList(index, size, tp, categoryId, key, language string) (recommend, list, community []model.ServerAppList) {
4949

50-
keyName := fmt.Sprintf("list_%s_%s_%s_%s", index, size, tp, categoryId)
50+
keyName := fmt.Sprintf("list_%s_%s_%s_%s_%s", index, size, tp, categoryId, language)
5151

5252
if result, ok := Cache.Get(keyName); ok {
5353
res, ok := result.(string)
@@ -63,7 +63,7 @@ func (o *casaService) GetServerList(index, size, tp, categoryId, key string) (re
6363

6464
head["Authorization"] = GetToken()
6565

66-
listS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/newlist?index="+index+"&size="+size+"&rank="+tp+"&category_id="+categoryId+"&key="+key, head)
66+
listS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/newlist?index="+index+"&size="+size+"&rank="+tp+"&category_id="+categoryId+"&key="+key+"&language="+language, head)
6767

6868
json2.Unmarshal([]byte(gjson.Get(listS, "data.list").String()), &list)
6969
json2.Unmarshal([]byte(gjson.Get(listS, "data.recommend").String()), &recommend)
@@ -88,12 +88,12 @@ func (o *casaService) GetServerCategoryList() []model.ServerCategoryList {
8888

8989
return list
9090
}
91-
func (o *casaService) GetServerAppInfo(id, t string) model.ServerAppList {
91+
func (o *casaService) GetServerAppInfo(id, t string, language string) model.ServerAppList {
9292

9393
head := make(map[string]string)
9494

9595
head["Authorization"] = GetToken()
96-
infoS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/info/"+id+"?t="+t, head)
96+
infoS := httper2.Get(config.ServerInfo.ServerApi+"/v2/app/info/"+id+"?t="+t+"&language="+language, head)
9797

9898
info := model.ServerAppList{}
9999
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)

Diff for: service/zerotier.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,20 @@ import (
44
"bytes"
55
"errors"
66
"fmt"
7-
"github.com/IceWhaleTech/CasaOS/pkg/config"
8-
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
9-
httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
10-
"github.com/IceWhaleTech/CasaOS/pkg/zerotier"
11-
"github.com/PuerkitoBio/goquery"
12-
"github.com/tidwall/gjson"
137
"io/ioutil"
148
"math/rand"
159
"net/http"
1610
"strconv"
1711
"strings"
1812
"time"
13+
"unicode"
14+
15+
"github.com/IceWhaleTech/CasaOS/pkg/config"
16+
command2 "github.com/IceWhaleTech/CasaOS/pkg/utils/command"
17+
httper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/httper"
18+
"github.com/IceWhaleTech/CasaOS/pkg/zerotier"
19+
"github.com/PuerkitoBio/goquery"
20+
"github.com/tidwall/gjson"
1921
)
2022

2123
type ZeroTierService interface {
@@ -33,6 +35,7 @@ type ZeroTierService interface {
3335
DeleteMember(token string, id, mId string) interface{}
3436
DeleteNetwork(token, id string) interface{}
3537
GetJoinNetworks() string
38+
NetworkIdFilter(letter rune) bool
3639
}
3740
type zerotierStruct struct {
3841
}
@@ -333,6 +336,13 @@ func (c *zerotierStruct) GetJoinNetworks() string {
333336
return json
334337
}
335338

339+
func (c *zerotierStruct) NetworkIdFilter(letter rune) bool {
340+
if unicode.IsNumber(letter) || unicode.IsLetter(letter) {
341+
return true
342+
} else {
343+
return false
344+
}
345+
}
336346
func NewZeroTierService() ZeroTierService {
337347
//初始化client
338348
client = http.Client{Timeout: 30 * time.Second, CheckRedirect: func(req *http.Request, via []*http.Request) error {

Diff for: types/system.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package types
22

3-
const CURRENTVERSION = "0.2.6"
3+
const CURRENTVERSION = "0.2.7"
44

5-
const BODY = "<li>Fix a disk that cannot be formatted under certain circumstances</li><li>Add a bug report panel.</li>"
5+
const BODY = "<li>Apply multilingual support</li><li>Fix a security vulnerability</li>"

Diff for: web/js/2.js

+135-157
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: web/js/3.js

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)