Files
waf-platform/EdgeUser/internal/web/actions/default/portal/post.go
2026-02-04 20:27:13 +08:00

52 lines
1.1 KiB
Go

// 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()
}