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,102 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package posts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/user-ui/posts/postutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type CreateAction struct {
actionutils.ParentAction
}
func (this *CreateAction) Init() {
this.Nav("", "", "post")
this.SecondMenu("create")
}
func (this *CreateAction) RunGet(params struct{}) {
// products
this.Data["products"] = postutils.FindAllProductOptions(this.LangCode())
// categories
categoriesResp, err := this.RPC().PostCategoryRPC().FindAllPostCategories(this.AdminContext(), &pb.FindAllPostCategoriesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var categoryMaps = []maps.Map{}
for _, category := range categoriesResp.PostCategories {
categoryMaps = append(categoryMaps, maps.Map{
"id": category.Id,
"name": category.Name,
})
}
this.Data["categories"] = categoryMaps
this.Show()
}
func (this *CreateAction) RunPost(params struct {
ProductCode string
CategoryId int64
Subject string
Type string
Body string
Url string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
var postId int64
defer func() {
this.CreateLogInfo(codes.Post_LogCreatePost, postId)
}()
params.Must.
Field("productCode", params.ProductCode).
Require("请选择所属产品").
Field("categoryId", params.CategoryId).
Gt(0, "请选择文章分类").
Field("subject", params.Subject).
Require("文章标题不能为空")
switch params.Type {
case "normal":
if len(params.Body) == 0 {
this.FailField("body", "请输入文章内容")
return
}
params.Url = ""
case "url":
if len(params.Url) == 0 {
this.FailField("url", "请输入文章URL")
return
}
params.Body = ""
default:
this.FailField("type", "请选择正确的类型")
return
}
createResp, err := this.RPC().PostRPC().CreatePost(this.AdminContext(), &pb.CreatePostRequest{
ProductCode: params.ProductCode,
PostCategoryId: params.CategoryId,
Type: params.Type,
Subject: params.Subject,
Url: params.Url,
Body: params.Body,
})
if err != nil {
this.ErrorPage(err)
return
}
postId = createResp.PostId
this.Success()
}

View File

@@ -0,0 +1,28 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package posts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type DeleteAction struct {
actionutils.ParentAction
}
func (this *DeleteAction) RunPost(params struct {
PostId int64
}) {
defer this.CreateLogInfo(codes.Post_LogDeletePost, params.PostId)
_, err := this.RPC().PostRPC().DeletePost(this.AdminContext(), &pb.DeletePostRequest{PostId: params.PostId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,91 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package posts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/user-ui/posts/postutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type IndexAction struct {
actionutils.ParentAction
}
func (this *IndexAction) Init() {
this.Nav("", "", "post")
this.SecondMenu("index")
}
func (this *IndexAction) RunGet(params struct {
CategoryId int64
}) {
// categories
categoriesResp, err := this.RPC().PostCategoryRPC().FindAllPostCategories(this.AdminContext(), &pb.FindAllPostCategoriesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var categoryMaps = []maps.Map{}
for _, category := range categoriesResp.PostCategories {
categoryMaps = append(categoryMaps, maps.Map{
"id": category.Id,
"isOn": category.IsOn,
"name": category.Name,
})
}
this.Data["categories"] = categoryMaps
// posts count
countResp, err := this.RPC().PostRPC().CountPosts(this.AdminContext(), &pb.CountPostsRequest{
PostCategoryId: params.CategoryId,
})
if err != nil {
this.ErrorPage(err)
return
}
var page = this.NewPage(countResp.Count)
this.Data["page"] = page.AsHTML()
// posts
postsResp, err := this.RPC().PostRPC().ListPosts(this.AdminContext(), &pb.ListPostsRequest{
Offset: page.Offset,
Size: page.Size,
PostCategoryId: params.CategoryId,
PostCategoryCode: "",
PublishedOnly: false,
ContainsBody: false,
})
if err != nil {
this.ErrorPage(err)
return
}
var postMaps = []maps.Map{}
for _, post := range postsResp.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,
"productName": postutils.FindProductName(this.LangCode(), post.ProductCode),
"subject": post.Subject,
"type": post.Type,
"isPublished": post.IsPublished,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", post.CreatedAt),
"category": categoryMap,
})
}
this.Data["posts"] = postMaps
this.Show()
}

View File

@@ -0,0 +1,60 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package posts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/user-ui/posts/postutils"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/maps"
timeutil "github.com/iwind/TeaGo/utils/time"
)
type PostAction struct {
actionutils.ParentAction
}
func (this *PostAction) Init() {
this.Nav("", "", "")
this.SecondMenu("index")
}
func (this *PostAction) RunGet(params struct {
PostId int64
}) {
postResp, err := this.RPC().PostRPC().FindPost(this.AdminContext(), &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
}
var categoryMap = maps.Map{
"id": 0,
}
if post.PostCategory != nil {
categoryMap = maps.Map{
"id": post.PostCategory.Id,
"name": post.PostCategory.Name,
}
}
this.Data["post"] = maps.Map{
"id": post.Id,
"productName": postutils.FindProductName(this.LangCode(), post.ProductCode),
"subject": post.Subject,
"type": post.Type,
"isPublished": post.IsPublished,
"createdTime": timeutil.FormatTime("Y-m-d H:i:s", post.CreatedAt),
"url": post.Url,
"body": post.Body,
"category": categoryMap,
}
this.Show()
}

View File

@@ -0,0 +1,37 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
package postutils
import (
"github.com/TeaOSLab/EdgeCommon/pkg/langs"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/iwind/TeaGo/maps"
)
// FindAllProductOptions product code options
func FindAllProductOptions(langCode langs.LangCode) []maps.Map {
return []maps.Map{
{
"name": "CDN",
"code": "cdn",
},
{
"name": "DNS",
"code": "dns",
},
{
"name": langs.Message(langCode, codes.Post_ProductGlobal),
"code": "global",
},
}
}
// FindProductName find product name with product code
func FindProductName(langCode langs.LangCode, code string) string {
for _, m := range FindAllProductOptions(langCode) {
if m.GetString("code") == code {
return m.GetString("name")
}
}
return ""
}

View File

@@ -0,0 +1,28 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package posts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
)
type PublishAction struct {
actionutils.ParentAction
}
func (this *PublishAction) RunPost(params struct {
PostId int64
}) {
defer this.CreateLogInfo(codes.Post_LogPublishPost, params.PostId)
_, err := this.RPC().PostRPC().PublishPost(this.AdminContext(), &pb.PublishPostRequest{PostId: params.PostId})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}

View File

@@ -0,0 +1,129 @@
// Copyright 2024 GoEdge CDN goedge.cdn@gmail.com. All rights reserved. Official site: https://goedge.cn .
//go:build plus
package posts
import (
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/actionutils"
"github.com/TeaOSLab/EdgeAdmin/internal/web/actions/default/settings/user-ui/posts/postutils"
"github.com/TeaOSLab/EdgeCommon/pkg/langs/codes"
"github.com/TeaOSLab/EdgeCommon/pkg/rpc/pb"
"github.com/iwind/TeaGo/actions"
"github.com/iwind/TeaGo/maps"
)
type UpdateAction struct {
actionutils.ParentAction
}
func (this *UpdateAction) Init() {
this.Nav("", "", "post")
this.SecondMenu("index")
}
func (this *UpdateAction) RunGet(params struct {
PostId int64
}) {
// products
this.Data["products"] = postutils.FindAllProductOptions(this.LangCode())
// categories
categoriesResp, err := this.RPC().PostCategoryRPC().FindAllPostCategories(this.AdminContext(), &pb.FindAllPostCategoriesRequest{})
if err != nil {
this.ErrorPage(err)
return
}
var categoryMaps = []maps.Map{}
for _, category := range categoriesResp.PostCategories {
categoryMaps = append(categoryMaps, maps.Map{
"id": category.Id,
"name": category.Name,
})
}
this.Data["categories"] = categoryMaps
// post information
postResp, err := this.RPC().PostRPC().FindPost(this.AdminContext(), &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
}
this.Data["post"] = maps.Map{
"id": post.Id,
"productCode": post.ProductCode,
"subject": post.Subject,
"type": post.Type,
"isPublished": post.IsPublished,
"url": post.Url,
"body": post.Body,
"categoryId": post.PostCategoryId,
}
this.Show()
}
func (this *UpdateAction) RunPost(params struct {
PostId int64
ProductCode string
CategoryId int64
Subject string
Type string
Body string
Url string
Must *actions.Must
CSRF *actionutils.CSRF
}) {
defer this.CreateLogInfo(codes.Post_LogUpdatePost, params.PostId)
params.Must.
Field("postId", params.PostId).
Gt(0, "请选择要修改的文章").
Field("productCode", params.ProductCode).
Require("请选择所属产品").
Field("categoryId", params.CategoryId).
Gt(0, "请选择文章分类").
Field("subject", params.Subject).
Require("文章标题不能为空")
switch params.Type {
case "normal":
if len(params.Body) == 0 {
this.FailField("body", "请输入文章内容")
return
}
params.Url = ""
case "url":
if len(params.Url) == 0 {
this.FailField("url", "请输入文章URL")
return
}
params.Body = ""
default:
this.FailField("type", "请选择正确的类型")
return
}
_, err := this.RPC().PostRPC().UpdatePost(this.AdminContext(), &pb.UpdatePostRequest{
PostId: params.PostId,
ProductCode: params.ProductCode,
PostCategoryId: params.CategoryId,
Type: params.Type,
Subject: params.Subject,
Url: params.Url,
Body: params.Body,
})
if err != nil {
this.ErrorPage(err)
return
}
this.Success()
}