Initial commit (code only without large binaries)
This commit is contained in:
205
EdgeAdmin/internal/web/actions/default/settings/ui/index.go
Normal file
205
EdgeAdmin/internal/web/actions/default/settings/ui/index.go
Normal file
@@ -0,0 +1,205 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/nodeconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/actions"
|
||||
"io"
|
||||
)
|
||||
|
||||
type IndexAction struct {
|
||||
actionutils.ParentAction
|
||||
}
|
||||
|
||||
func (this *IndexAction) Init() {
|
||||
this.Nav("", "", "")
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunGet(params struct{}) {
|
||||
config, err := configloaders.LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
if config.DefaultPageSize == 0 {
|
||||
config.DefaultPageSize = 10
|
||||
}
|
||||
this.Data["config"] = config
|
||||
|
||||
// 时区
|
||||
this.Data["timeZoneGroups"] = nodeconfigs.FindAllTimeZoneGroups()
|
||||
this.Data["timeZoneLocations"] = nodeconfigs.FindAllTimeZoneLocations()
|
||||
|
||||
if len(config.TimeZone) == 0 {
|
||||
config.TimeZone = nodeconfigs.DefaultTimeZoneLocation
|
||||
}
|
||||
this.Data["timeZoneLocation"] = nodeconfigs.FindTimeZoneLocation(config.TimeZone)
|
||||
|
||||
this.filterConfig(config)
|
||||
|
||||
this.Show()
|
||||
}
|
||||
|
||||
func (this *IndexAction) RunPost(params struct {
|
||||
ProductName string
|
||||
AdminSystemName string
|
||||
ShowFinance bool
|
||||
ShowVersion bool
|
||||
Version string
|
||||
FaviconFile *actions.File
|
||||
LogoFile *actions.File
|
||||
DefaultPageSize int
|
||||
TimeZone string
|
||||
DnsResolverType string
|
||||
|
||||
SupportModuleCDN bool
|
||||
SupportModuleNS bool
|
||||
|
||||
Must *actions.Must
|
||||
CSRF *actionutils.CSRF
|
||||
}) {
|
||||
defer this.CreateLogInfo(codes.AdminUI_LogUpdateUISettings)
|
||||
|
||||
params.Must.
|
||||
Field("productName", params.ProductName).
|
||||
Require("请输入产品名称").
|
||||
Field("adminSystemName", params.AdminSystemName).
|
||||
Require("请输入管理员系统名称").
|
||||
Field("defaultPageSize", params.DefaultPageSize).
|
||||
Gte(0, "默认每页显示数不能小于0").
|
||||
Lte(100, "默认每页显示数不能大于100")
|
||||
|
||||
config, err := configloaders.LoadAdminUIConfig()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
config.ProductName = params.ProductName
|
||||
config.AdminSystemName = params.AdminSystemName
|
||||
// ShowOpenSourceInfo 选项已移除,保持默认值
|
||||
config.ShowFinance = params.ShowFinance
|
||||
config.ShowVersion = params.ShowVersion
|
||||
config.Version = params.Version
|
||||
config.TimeZone = params.TimeZone
|
||||
config.DNSResolver.Type = params.DnsResolverType
|
||||
|
||||
if params.DefaultPageSize > 0 {
|
||||
config.DefaultPageSize = params.DefaultPageSize
|
||||
} else {
|
||||
config.DefaultPageSize = 10
|
||||
}
|
||||
|
||||
config.Modules = []userconfigs.UserModule{}
|
||||
if params.SupportModuleCDN {
|
||||
config.Modules = append(config.Modules, userconfigs.UserModuleCDN)
|
||||
}
|
||||
if params.SupportModuleNS {
|
||||
config.Modules = append(config.Modules, userconfigs.UserModuleNS)
|
||||
}
|
||||
|
||||
// 上传Favicon文件
|
||||
if params.FaviconFile != nil {
|
||||
createResp, err := this.RPC().FileRPC().CreateFile(this.AdminContext(), &pb.CreateFileRequest{
|
||||
Filename: params.FaviconFile.Filename,
|
||||
Size: params.FaviconFile.Size,
|
||||
IsPublic: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var fileId = createResp.FileId
|
||||
|
||||
// 上传内容
|
||||
var buf = make([]byte, 512*1024)
|
||||
reader, err := params.FaviconFile.OriginFile.Open()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for {
|
||||
n, err := reader.Read(buf)
|
||||
if n > 0 {
|
||||
_, err = this.RPC().FileChunkRPC().CreateFileChunk(this.AdminContext(), &pb.CreateFileChunkRequest{
|
||||
FileId: fileId,
|
||||
Data: buf[:n],
|
||||
})
|
||||
if err != nil {
|
||||
this.Fail("上传失败:" + err.Error())
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
this.Fail("上传失败:" + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 置为已完成
|
||||
_, err = this.RPC().FileRPC().UpdateFileFinished(this.AdminContext(), &pb.UpdateFileFinishedRequest{FileId: fileId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
}
|
||||
config.FaviconFileId = fileId
|
||||
}
|
||||
|
||||
// 上传Logo文件
|
||||
if params.LogoFile != nil {
|
||||
createResp, err := this.RPC().FileRPC().CreateFile(this.AdminContext(), &pb.CreateFileRequest{
|
||||
Filename: params.LogoFile.Filename,
|
||||
Size: params.LogoFile.Size,
|
||||
IsPublic: true,
|
||||
})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
var fileId = createResp.FileId
|
||||
|
||||
// 上传内容
|
||||
var buf = make([]byte, 512*1024)
|
||||
reader, err := params.LogoFile.OriginFile.Open()
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
for {
|
||||
n, err := reader.Read(buf)
|
||||
if n > 0 {
|
||||
_, err = this.RPC().FileChunkRPC().CreateFileChunk(this.AdminContext(), &pb.CreateFileChunkRequest{
|
||||
FileId: fileId,
|
||||
Data: buf[:n],
|
||||
})
|
||||
if err != nil {
|
||||
this.Fail("上传失败:" + err.Error())
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
if err == io.EOF {
|
||||
break
|
||||
}
|
||||
this.Fail("上传失败:" + err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
// 置为已完成
|
||||
_, err = this.RPC().FileRPC().UpdateFileFinished(this.AdminContext(), &pb.UpdateFileFinishedRequest{FileId: fileId})
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
}
|
||||
config.LogoFileId = fileId
|
||||
}
|
||||
|
||||
err = configloaders.UpdateAdminUIConfig(config)
|
||||
if err != nil {
|
||||
this.ErrorPage(err)
|
||||
return
|
||||
}
|
||||
|
||||
this.Success()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build !plus
|
||||
|
||||
package ui
|
||||
|
||||
import "github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
|
||||
func (this *IndexAction) filterConfig(config *systemconfigs.AdminUIConfig) {
|
||||
this.Data["supportModuleCDN"] = true
|
||||
this.Data["supportModuleNS"] = true
|
||||
this.Data["nsIsVisible"] = false
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||
//go:build plus
|
||||
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/plus"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/systemconfigs"
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/userconfigs"
|
||||
"github.com/iwind/TeaGo/lists"
|
||||
)
|
||||
|
||||
func (this *IndexAction) filterConfig(config *systemconfigs.AdminUIConfig) {
|
||||
// 模块
|
||||
if len(config.Modules) == 0 {
|
||||
config.Modules = []userconfigs.UserModule{userconfigs.UserModuleCDN, userconfigs.UserModuleNS}
|
||||
}
|
||||
this.Data["supportModuleCDN"] = lists.ContainsString(config.Modules, userconfigs.UserModuleCDN)
|
||||
this.Data["supportModuleNS"] = lists.ContainsString(config.Modules, userconfigs.UserModuleNS)
|
||||
this.Data["nsIsVisible"] = plus.AllowComponent(plus.ComponentCodeNS)
|
||||
}
|
||||
19
EdgeAdmin/internal/web/actions/default/settings/ui/init.go
Normal file
19
EdgeAdmin/internal/web/actions/default/settings/ui/init.go
Normal file
@@ -0,0 +1,19 @@
|
||||
package ui
|
||||
|
||||
import (
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/configloaders"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/settingutils"
|
||||
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
|
||||
"github.com/iwind/TeaGo"
|
||||
)
|
||||
|
||||
func init() {
|
||||
TeaGo.BeforeStart(func(server *TeaGo.Server) {
|
||||
server.
|
||||
Helper(helpers.NewUserMustAuth(configloaders.AdminModuleCodeCommon)).
|
||||
Helper(settingutils.NewHelper("ui")).
|
||||
Prefix("/settings/ui").
|
||||
GetPost("", new(IndexAction)).
|
||||
EndAll()
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user