This commit is contained in:
unknown
2026-02-04 20:27:13 +08:00
commit 3b042d1dad
9410 changed files with 1488147 additions and 0 deletions

View File

@@ -0,0 +1,26 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package portal
import (
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
"github.com/iwind/TeaGo/actions"
"net/http"
)
type Helper struct {
}
func (this *Helper) BeforeAction(action *actions.ActionObject) (goNext bool) {
uiConfig, _ := configloaders.LoadUIConfig()
if uiConfig != nil {
goNext = uiConfig.Portal.IsOn
}
if !goNext {
action.ResponseWriter.WriteHeader(http.StatusNotFound)
_, _ = action.ResponseWriter.Write([]byte("page not found '" + action.Request.URL.String() + "'"))
}
return
}

View File

@@ -0,0 +1,20 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package portal
import "github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
type IndexAction struct {
actionutils.PortalAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
// 检测是否自动跳转到HTTPS
this.CheckHTTPSRedirecting()
this.Show()
}

View File

@@ -0,0 +1,34 @@
// Copyright 2024 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
package portal
import (
"github.com/TeaOSLab/EdgeUser/internal/web/actions/default/portal/products/cdn"
"github.com/iwind/TeaGo"
"github.com/iwind/TeaGo/Tea"
)
func init() {
TeaGo.BeforeStart(func(server *TeaGo.Server) {
server.
Prefix("/portal").
Helper(new(Helper)).
Get("", new(IndexAction)).
// cdn
Get("/products/cdn", new(cdn.IndexAction)).
//common
Get("/post", new(PostAction)).
Get("/layout", new(LayoutAction)).
//assets
Static("/portal/assets", Tea.Root+"/portal/assets").
// others
Get(`/:filename(.+)`, new(WildcardAction)).
//
EndAll()
})
}

View File

@@ -0,0 +1,76 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package portal
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
teaconst "github.com/TeaOSLab/EdgeUser/internal/const"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeUser/internal/web/helpers"
"github.com/iwind/TeaGo/maps"
"github.com/iwind/TeaGo/types"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type LayoutAction struct {
actionutils.PortalAction
}
func (this *LayoutAction) Init() {
this.Nav("", "", "")
}
func (this *LayoutAction) RunGet(params struct {
Auth *helpers.UserShouldAuth
}) {
// is logged?
this.Data["userIsLogged"] = params.Auth != nil && params.Auth.UserId() > 0
// service
{
postResp, err := this.RPC().PostRPC().ListPosts(this.UserContext(), &pb.ListPostsRequest{
Offset: 0,
Size: 5,
ProductCode: "global",
PostCategoryId: 0,
PostCategoryCode: "support",
ExcludingPostCategoryCode: "",
PublishedOnly: true,
ContainsBody: false,
})
if err != nil {
this.ErrorPage(err)
return
}
var postMaps = []maps.Map{}
for _, post := range postResp.Posts {
postMaps = append(postMaps, maps.Map{
"id": post.Id,
"subject": post.Subject,
"publishedTime": timeutil.FormatTime("Y-m-d", post.PublishedAt),
})
}
this.Data["supportPosts"] = postMaps
}
// product name, logo ...
uiConfig, err := configloaders.LoadUIConfig()
if err != nil {
this.ErrorPage(err)
return
}
var productName = teaconst.ProductName
if uiConfig != nil && len(uiConfig.ProductName) > 0 {
productName = uiConfig.ProductName
}
this.Data["productName"] = productName
var logoURL = ""
if uiConfig != nil && uiConfig.Portal.LogoFileId > 0 {
logoURL = "/ui/image/" + types.String(uiConfig.Portal.LogoFileId)
}
this.Data["logoURL"] = logoURL
this.Success()
}

View File

@@ -0,0 +1,51 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package portal
import (
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
"net/http"
)
type PostAction struct {
actionutils.PortalAction
}
func (this *PostAction) Init() {
this.Nav("", "", "")
}
func (this *PostAction) RunGet(params struct {
PostId int64
}) {
postResp, err := this.RPC().PostRPC().FindPost(this.UserContext(), &pb.FindPostRequest{PostId: params.PostId})
if err != nil {
this.ErrorPage(err)
return
}
var post = postResp.Post
if post == nil {
this.NotFound("post", params.PostId)
return
}
if post.Type == "url" {
this.Redirect(post.Url, http.StatusFound)
return
}
this.Data["post"] = maps.Map{
"id": post.Id,
"subject": post.Subject,
"type": post.Type,
"url": post.Url,
"body": post.Body,
"publishedTime": timeutil.FormatTime("Y-m-d H:i:s", post.PublishedAt),
}
this.Show()
}

View File

@@ -0,0 +1,103 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package cdn
import (
"encoding/json"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
"github.com/TeaOSLab/EdgeUser/internal/configloaders"
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.PortalAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "")
}
func (this *IndexAction) RunGet(params struct{}) {
// activities
{
postResp, err := this.RPC().PostRPC().ListPosts(this.UserContext(), &pb.ListPostsRequest{
Offset: 0,
Size: 9,
ProductCode: "cdn",
PostCategoryId: 0,
PostCategoryCode: "",
ExcludingPostCategoryCode: "support",
PublishedOnly: true,
ContainsBody: false,
})
if err != nil {
this.ErrorPage(err)
return
}
var postMaps = []maps.Map{}
for _, post := range postResp.Posts {
var categoryMap = maps.Map{"id": 0}
if post.PostCategory != nil {
categoryMap = maps.Map{
"id": post.PostCategory.Id,
"name": post.PostCategory.Name,
}
}
postMaps = append(postMaps, maps.Map{
"id": post.Id,
"subject": post.Subject,
"publishedTime": timeutil.FormatTime("Y-m-d", post.PublishedAt),
"category": categoryMap,
})
}
this.Data["latestPosts"] = postMaps
}
// plans
priceConfig, _ := configloaders.LoadUserPriceConfig()
if priceConfig != nil && priceConfig.IsOn && priceConfig.EnablePlans {
plansResp, err := this.RPC().PlanRPC().FindAllAvailablePlans(this.UserContext(), &pb.FindAllAvailablePlansRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var planMaps = []maps.Map{}
for _, plan := range plansResp.Plans {
// 流量限制
// traffic limit
var trafficLimitConfig = &serverconfigs.TrafficLimitConfig{}
if len(plan.TrafficLimitJSON) > 0 {
err = json.Unmarshal(plan.TrafficLimitJSON, trafficLimitConfig)
if err != nil {
this.ErrorPage(err)
return
}
}
planMaps = append(planMaps, maps.Map{
"id": plan.Id,
"name": plan.Name,
"description": plan.Description,
"totalServers": plan.TotalServers,
"dailyRequests": plan.DailyRequests,
"dailyRequestsFormat": plan.DailyRequests,
"trafficLimit": trafficLimitConfig,
"priceType": plan.PriceType,
"monthlyPrice": plan.MonthlyPrice,
"seasonallyPrice": plan.SeasonallyPrice,
"yearlyPrice": plan.YearlyPrice,
})
}
this.Data["plans"] = planMaps
} else {
this.Data["plans"] = []maps.Map{}
}
this.Show()
}

View File

@@ -0,0 +1,60 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package portal
import (
"github.com/TeaOSLab/EdgeUser/internal/web/actions/actionutils"
"github.com/iwind/TeaGo/Tea"
"net/http"
"os"
"regexp"
"strings"
)
type WildcardAction struct {
actionutils.PortalAction
}
func (this *WildcardAction) Init() {
this.Nav("", "", "")
}
func (this *WildcardAction) RunGet(params struct {
Filename string
}) {
var pieces = strings.Split(params.Filename, "/")
var reg = regexp.MustCompile(`^[@\w+.]+$`)
for _, piece := range pieces {
if !reg.MatchString(piece) {
this.ResponseWriter.Header().Set("Content-Type", "text/plain; charset=utf-8") // prevent html injection
this.ResponseWriter.WriteHeader(http.StatusBadRequest)
this.WriteString("invalid url '" + params.Filename + "'")
return
}
}
// check file
var paths = []string{
"/portal/" + params.Filename + ".html",
"/portal/" + params.Filename + "/index.html",
}
var foundPath string
var found = false
for _, path := range paths {
_, err := os.Stat(Tea.Root + path)
if err == nil {
found = true
foundPath = path
break
}
}
if !found {
this.ResponseWriter.WriteHeader(http.StatusNotFound)
this.WriteString("page not found '" + params.Filename + "'")
return
}
this.View(foundPath)
this.Show()
}