调整目录结构

This commit is contained in:
刘祥超
2020-11-27 15:18:32 +08:00
parent e3eeee146b
commit 534a3f77f8
42 changed files with 56 additions and 199 deletions

View File

@@ -1,7 +1,6 @@
package cache
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
@@ -11,7 +10,8 @@ func init() {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Helper(componentutils.NewComponentHelper()).
Data("teaMenu", "servers").
Data("teaSubMenu", "cache").
Prefix("/servers/components/cache").
Get("", new(IndexAction)).
GetPost("/createPopup", new(CreatePopupAction)).

View File

@@ -1,87 +0,0 @@
package componentutils
import (
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
"net/http"
)
type ComponentHelper struct {
}
func NewComponentHelper() *ComponentHelper {
return &ComponentHelper{}
}
func (this *ComponentHelper) BeforeAction(action *actions.ActionObject) {
if action.Request.Method != http.MethodGet {
return
}
action.Data["teaMenu"] = "servers"
action.Data["teaSubMenu"] = "components"
action.Data["mainTab"] = "component"
// 创建左侧菜单
secondMenuItem := action.Data.GetString("secondMenuItem")
action.Data["leftMenuItems"] = this.createLeftMenus(secondMenuItem)
}
func (this *ComponentHelper) createLeftMenus(secondMenuItem string) (items []maps.Map) {
items = append(items, maps.Map{
"name": "通用设置",
"url": "/servers/components",
"isActive": secondMenuItem == "global",
})
items = append(items, maps.Map{
"name": "服务分组",
"url": "/servers/components/groups",
"isActive": secondMenuItem == "group",
})
items = append(items, maps.Map{
"name": "缓存策略",
"url": "/servers/components/cache",
"isActive": secondMenuItem == "cache",
})
items = append(items, maps.Map{
"name": "WAF策略",
"url": "/servers/components/waf",
"isActive": secondMenuItem == "waf",
})
items = append(items, maps.Map{
"name": "日志策略",
"url": "/servers/components/log",
"isActive": secondMenuItem == "log",
})
items = append(items, maps.Map{
"name": "IP库",
"url": "/servers/components/ip-library",
"isActive": secondMenuItem == "ip-library",
})
/**items = append(items, maps.Map{
"name": "Gzip规则",
"url": "/servers/components/gzip",
"isActive": secondMenuItem == "gzip",
})
items = append(items, maps.Map{
"name": "路径规则",
"url": "/servers/components/location",
"isActive": secondMenuItem == "location",
})
items = append(items, maps.Map{
"name": "重写规则",
"url": "/servers/components/rewrite",
"isActive": secondMenuItem == "write",
})
items = append(items, maps.Map{
"name": "源站",
"url": "/servers/components/origin",
"isActive": secondMenuItem == "origin",
})
items = append(items, maps.Map{
"name": "变量",
"url": "/servers/components/variable",
"isActive": secondMenuItem == "variable",
})**/
return
}

View File

@@ -17,6 +17,7 @@ func (this *Helper) BeforeAction(action *actions.ActionObject) {
return
}
action.Data["teaMenu"] = "servers"
action.Data["mainTab"] = "component"
action.Data["secondMenuItem"] = "group"
}

View File

@@ -1,7 +1,6 @@
package groups
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
@@ -11,7 +10,7 @@ func init() {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Helper(componentutils.NewComponentHelper()).
Data("teaSubMenu", "group").
Prefix("/servers/components/groups").
Get("", new(IndexAction)).
GetPost("/createPopup", new(CreatePopupAction)).

View File

@@ -1,7 +1,6 @@
package components
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
@@ -10,8 +9,8 @@ func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Data("teaSubMenu", "global").
Helper(NewHelper()).
Helper(componentutils.NewComponentHelper()).
Prefix("/servers/components").
GetPost("", new(IndexAction)).
EndAll()

View File

@@ -1,26 +0,0 @@
package iplibrary
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
LibraryId int64
}) {
// 创建日志
defer this.CreateLog(oplogs.LevelInfo, "删除IP库 %d", params.LibraryId)
_, err := this.RPC().IPLibraryRPC().DeleteIPLibrary(this.AdminContext(), &pb.DeleteIPLibraryRequest{IpLibraryId: params.LibraryId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -1,50 +0,0 @@
package iplibrary
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DownloadAction struct {
actionutils.ParentAction
}
func (this *DownloadAction) Init() {
this.Nav("", "", "")
}
func (this *DownloadAction) RunGet(params struct {
LibraryId int64
}) {
// 日志
defer this.CreateLog(oplogs.LevelInfo, "下载IP库 %d", params.LibraryId)
libraryResp, err := this.RPC().IPLibraryRPC().FindEnabledIPLibrary(this.AdminContext(), &pb.FindEnabledIPLibraryRequest{IpLibraryId: params.LibraryId})
if err != nil {
this.ErrorPage(err)
return
}
if libraryResp.IpLibrary == nil || libraryResp.IpLibrary.File == nil {
this.NotFound("ipLibrary", params.LibraryId)
return
}
file := libraryResp.IpLibrary.File
chunkIdsResp, err := this.RPC().FileChunkRPC().FindAllFileChunkIds(this.AdminContext(), &pb.FindAllFileChunkIdsRequest{FileId: file.Id})
if err != nil {
this.ErrorPage(err)
}
this.AddHeader("Content-Disposition", "attachment; filename=\""+file.Filename+"\";")
for _, chunkId := range chunkIdsResp.FileChunkIds {
chunkResp, err := this.RPC().FileChunkRPC().DownloadFileChunk(this.AdminContext(), &pb.DownloadFileChunkRequest{FileChunkId: chunkId})
if err != nil {
this.ErrorPage(err)
return
}
if chunkResp.FileChunk != nil {
this.Write(chunkResp.FileChunk.Data)
}
}
}

View File

@@ -1,22 +0,0 @@
package iplibrary
import (
"github.com/iwind/TeaGo/actions"
"net/http"
)
type Helper struct {
}
func NewHelper() *Helper {
return &Helper{}
}
func (this *Helper) BeforeAction(action *actions.ActionObject) {
if action.Request.Method != http.MethodGet {
return
}
action.Data["mainTab"] = "component"
action.Data["secondMenuItem"] = "ip-library"
}

View File

@@ -1,56 +0,0 @@
package iplibrary
import (
"fmt"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.FirstMenu("index")
}
func (this *IndexAction) RunGet(params struct {
Type string
}) {
if len(params.Type) == 0 {
params.Type = serverconfigs.IPLibraryTypes[0].GetString("code")
}
this.Data["types"] = serverconfigs.IPLibraryTypes
this.Data["selectedType"] = params.Type
// 列表
listResp, err := this.RPC().IPLibraryRPC().FindAllEnabledIPLibrariesWithType(this.AdminContext(), &pb.FindAllEnabledIPLibrariesWithTypeRequest{Type: params.Type})
if err != nil {
this.ErrorPage(err)
return
}
libraryMaps := []maps.Map{}
for _, library := range listResp.IpLibraries {
var fileMap maps.Map = nil
if library.File != nil {
fileMap = maps.Map{
"id": library.File.Id,
"filename": library.File.Filename,
"sizeMB": fmt.Sprintf("%.2f", float64(library.File.Size)/1024/1024),
}
}
libraryMaps = append(libraryMaps, maps.Map{
"id": library.Id,
"file": fileMap,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", library.CreatedAt),
})
}
this.Data["libraries"] = libraryMaps
this.Show()
}

View File

@@ -1,22 +0,0 @@
package iplibrary
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Helper(componentutils.NewComponentHelper()).
Prefix("/servers/components/ip-library").
Get("", new(IndexAction)).
GetPost("/uploadPopup", new(UploadPopupAction)).
Post("/delete", new(DeleteAction)).
Get("/download", new(DownloadAction)).
EndAll()
})
}

View File

@@ -1,110 +0,0 @@
package iplibrary
import (
"github.com/TeaOSLab/EdgeAdmin/internal/oplogs"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/iwind/TeaGo/actions"
"io"
)
type UploadPopupAction struct {
actionutils.ParentAction
}
func (this *UploadPopupAction) Init() {
this.Nav("", "", "")
}
func (this *UploadPopupAction) RunGet(params struct{}) {
this.Data["types"] = serverconfigs.IPLibraryTypes
this.Show()
}
func (this *UploadPopupAction) RunPost(params struct {
Type string
File *actions.File
Must *actions.Must
}) {
libraryType := serverconfigs.FindIPLibraryWithType(params.Type)
if libraryType == nil {
this.Fail("错误的IP类型")
}
if params.File == nil {
this.Fail("请选择要上传的文件")
}
if params.File.Size == 0 {
this.Fail("文件内容不能为空")
}
if params.File.Ext != libraryType.GetString("ext") {
this.Fail("IP库文件扩展名错误应该为" + libraryType.GetString("ext"))
}
reader, err := params.File.OriginFile.Open()
if err != nil {
this.ErrorPage(err)
return
}
defer func() {
_ = reader.Close()
}()
// 创建文件
fileResp, err := this.RPC().FileRPC().CreateFile(this.AdminContext(), &pb.CreateFileRequest{
Filename: params.File.Filename,
Size: params.File.Size,
})
if err != nil {
this.ErrorPage(err)
return
}
fileId := fileResp.FileId
// 上传内容
buf := make([]byte, 512*1024)
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)
}
// 保存
createResp, err := this.RPC().IPLibraryRPC().CreateIPLibrary(this.AdminContext(), &pb.CreateIPLibraryRequest{
Type: params.Type,
FileId: fileId,
})
if err != nil {
this.ErrorPage(err)
return
}
// 创建日志
defer this.CreateLog(oplogs.LevelInfo, "上传IP库 %d", createResp.IpLibraryId)
this.Success()
}

View File

@@ -1,7 +1,6 @@
package log
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
)
@@ -11,7 +10,6 @@ func init() {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Helper(componentutils.NewComponentHelper()).
Prefix("/servers/components/log").
Get("", new(IndexAction)).
EndAll()

View File

@@ -1,7 +1,6 @@
package waf
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/componentutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/servers/components/waf/ipadmin"
"github.com/TeaOSLab/EdgeAdmin/internal/web/helpers"
"github.com/iwind/TeaGo"
@@ -12,7 +11,8 @@ func init() {
server.
Helper(helpers.NewUserMustAuth()).
Helper(NewHelper()).
Helper(componentutils.NewComponentHelper()).
Data("teaMenu", "servers").
Data("teaSubMenu", "waf").
Prefix("/servers/components/waf").
Get("", new(IndexAction)).
GetPost("/createPopup", new(CreatePopupAction)).