目录调整
|
@ -5,11 +5,11 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/actions/common"
|
|
||||||
"github/fthvgb1/wp-go/cache"
|
"github/fthvgb1/wp-go/cache"
|
||||||
"github/fthvgb1/wp-go/config"
|
"github/fthvgb1/wp-go/config"
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
"github/fthvgb1/wp-go/internal/actions/common"
|
||||||
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/mail"
|
"github/fthvgb1/wp-go/mail"
|
||||||
"io"
|
"io"
|
|
@ -3,9 +3,9 @@ package common
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
"github/fthvgb1/wp-go/internal/wp"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/models"
|
"github/fthvgb1/wp-go/models"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
|
@ -5,21 +5,21 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github/fthvgb1/wp-go/cache"
|
"github/fthvgb1/wp-go/cache"
|
||||||
"github/fthvgb1/wp-go/config"
|
"github/fthvgb1/wp-go/config"
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
wp2 "github/fthvgb1/wp-go/internal/wp"
|
||||||
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/models"
|
"github/fthvgb1/wp-go/models"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var postContextCache *cache.MapCache[uint64, PostContext]
|
var postContextCache *cache.MapCache[uint64, PostContext]
|
||||||
var archivesCaches *Arch
|
var archivesCaches *Arch
|
||||||
var categoryCaches *cache.SliceCache[wp.TermsMy]
|
var categoryCaches *cache.SliceCache[wp2.TermsMy]
|
||||||
var recentPostsCaches *cache.SliceCache[wp.Posts]
|
var recentPostsCaches *cache.SliceCache[wp2.Posts]
|
||||||
var recentCommentsCaches *cache.SliceCache[wp.Comments]
|
var recentCommentsCaches *cache.SliceCache[wp2.Comments]
|
||||||
var postCommentCaches *cache.MapCache[uint64, []uint64]
|
var postCommentCaches *cache.MapCache[uint64, []uint64]
|
||||||
var postsCache *cache.MapCache[uint64, wp.Posts]
|
var postsCache *cache.MapCache[uint64, wp2.Posts]
|
||||||
|
|
||||||
var postMetaCache *cache.MapCache[uint64, map[string]any]
|
var postMetaCache *cache.MapCache[uint64, map[string]any]
|
||||||
|
|
||||||
|
@ -28,9 +28,9 @@ var postListIdsCache *cache.MapCache[string, PostIds]
|
||||||
var searchPostIdsCache *cache.MapCache[string, PostIds]
|
var searchPostIdsCache *cache.MapCache[string, PostIds]
|
||||||
var maxPostIdCache *cache.SliceCache[uint64]
|
var maxPostIdCache *cache.SliceCache[uint64]
|
||||||
var TotalRaw int64
|
var TotalRaw int64
|
||||||
var usersCache *cache.MapCache[uint64, wp.Users]
|
var usersCache *cache.MapCache[uint64, wp2.Users]
|
||||||
var usersNameCache *cache.MapCache[string, wp.Users]
|
var usersNameCache *cache.MapCache[string, wp2.Users]
|
||||||
var commentsCache *cache.MapCache[uint64, wp.Comments]
|
var commentsCache *cache.MapCache[uint64, wp2.Comments]
|
||||||
|
|
||||||
func InitActionsCommonCache() {
|
func InitActionsCommonCache() {
|
||||||
c := config.Conf.Load()
|
c := config.Conf.Load()
|
||||||
|
@ -47,25 +47,25 @@ func InitActionsCommonCache() {
|
||||||
|
|
||||||
postContextCache = cache.NewMapCacheByFn[uint64, PostContext](getPostContext, c.ContextPostCacheTime)
|
postContextCache = cache.NewMapCacheByFn[uint64, PostContext](getPostContext, c.ContextPostCacheTime)
|
||||||
|
|
||||||
postsCache = cache.NewMapCacheByBatchFn[uint64, wp.Posts](getPostsByIds, c.PostDataCacheTime)
|
postsCache = cache.NewMapCacheByBatchFn[uint64, wp2.Posts](getPostsByIds, c.PostDataCacheTime)
|
||||||
|
|
||||||
postMetaCache = cache.NewMapCacheByBatchFn[uint64, map[string]any](getPostMetaByPostIds, c.PostDataCacheTime)
|
postMetaCache = cache.NewMapCacheByBatchFn[uint64, map[string]any](getPostMetaByPostIds, c.PostDataCacheTime)
|
||||||
|
|
||||||
categoryCaches = cache.NewSliceCache[wp.TermsMy](categories, c.CategoryCacheTime)
|
categoryCaches = cache.NewSliceCache[wp2.TermsMy](categories, c.CategoryCacheTime)
|
||||||
|
|
||||||
recentPostsCaches = cache.NewSliceCache[wp.Posts](recentPosts, c.RecentPostCacheTime)
|
recentPostsCaches = cache.NewSliceCache[wp2.Posts](recentPosts, c.RecentPostCacheTime)
|
||||||
|
|
||||||
recentCommentsCaches = cache.NewSliceCache[wp.Comments](recentComments, c.RecentCommentsCacheTime)
|
recentCommentsCaches = cache.NewSliceCache[wp2.Comments](recentComments, c.RecentCommentsCacheTime)
|
||||||
|
|
||||||
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, c.PostCommentsCacheTime)
|
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, c.PostCommentsCacheTime)
|
||||||
|
|
||||||
maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, c.MaxPostIdCacheTime)
|
maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, c.MaxPostIdCacheTime)
|
||||||
|
|
||||||
usersCache = cache.NewMapCacheByFn[uint64, wp.Users](getUserById, c.UserInfoCacheTime)
|
usersCache = cache.NewMapCacheByFn[uint64, wp2.Users](getUserById, c.UserInfoCacheTime)
|
||||||
|
|
||||||
usersNameCache = cache.NewMapCacheByFn[string, wp.Users](getUserByName, c.UserInfoCacheTime)
|
usersNameCache = cache.NewMapCacheByFn[string, wp2.Users](getUserByName, c.UserInfoCacheTime)
|
||||||
|
|
||||||
commentsCache = cache.NewMapCacheByBatchFn[uint64, wp.Comments](getCommentByIds, c.CommentsCacheTime)
|
commentsCache = cache.NewMapCacheByBatchFn[uint64, wp2.Comments](getCommentByIds, c.CommentsCacheTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ClearCache() {
|
func ClearCache() {
|
||||||
|
@ -97,13 +97,13 @@ type PostIds struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Arch struct {
|
type Arch struct {
|
||||||
data []wp.PostArchive
|
data []wp2.PostArchive
|
||||||
mutex *sync.Mutex
|
mutex *sync.Mutex
|
||||||
setCacheFunc func(context.Context) ([]wp.PostArchive, error)
|
setCacheFunc func(context.Context) ([]wp2.PostArchive, error)
|
||||||
month time.Month
|
month time.Month
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Arch) getArchiveCache(ctx context.Context) []wp.PostArchive {
|
func (c *Arch) getArchiveCache(ctx context.Context) []wp2.PostArchive {
|
||||||
l := len(c.data)
|
l := len(c.data)
|
||||||
m := time.Now().Month()
|
m := time.Now().Month()
|
||||||
if l > 0 && c.month != m || l < 1 {
|
if l > 0 && c.month != m || l < 1 {
|
||||||
|
@ -121,30 +121,30 @@ func (c *Arch) getArchiveCache(ctx context.Context) []wp.PostArchive {
|
||||||
}
|
}
|
||||||
|
|
||||||
type PostContext struct {
|
type PostContext struct {
|
||||||
prev wp.Posts
|
prev wp2.Posts
|
||||||
next wp.Posts
|
next wp2.Posts
|
||||||
}
|
}
|
||||||
|
|
||||||
func archives(ctx context.Context) ([]wp.PostArchive, error) {
|
func archives(ctx context.Context) ([]wp2.PostArchive, error) {
|
||||||
return models.Find[wp.PostArchive](ctx, models.SqlBuilder{
|
return models.Find[wp2.PostArchive](ctx, models.SqlBuilder{
|
||||||
{"post_type", "post"}, {"post_status", "publish"},
|
{"post_type", "post"}, {"post_status", "publish"},
|
||||||
}, "YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts", "year,month", models.SqlBuilder{{"year", "desc"}, {"month", "desc"}}, nil, nil, 0)
|
}, "YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts", "year,month", models.SqlBuilder{{"year", "desc"}, {"month", "desc"}}, nil, nil, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Archives(ctx context.Context) (r []wp.PostArchive) {
|
func Archives(ctx context.Context) (r []wp2.PostArchive) {
|
||||||
return archivesCaches.getArchiveCache(ctx)
|
return archivesCaches.getArchiveCache(ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Categories(ctx context.Context) []wp.TermsMy {
|
func Categories(ctx context.Context) []wp2.TermsMy {
|
||||||
r, err := categoryCaches.GetCache(ctx, time.Second, ctx)
|
r, err := categoryCaches.GetCache(ctx, time.Second, ctx)
|
||||||
logs.ErrPrintln(err, "get category ")
|
logs.ErrPrintln(err, "get category ")
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
func categories(a ...any) (terms []wp.TermsMy, err error) {
|
func categories(a ...any) (terms []wp2.TermsMy, err error) {
|
||||||
ctx := a[0].(context.Context)
|
ctx := a[0].(context.Context)
|
||||||
var in = []any{"category"}
|
var in = []any{"category"}
|
||||||
terms, err = models.Find[wp.TermsMy](ctx, models.SqlBuilder{
|
terms, err = models.Find[wp2.TermsMy](ctx, models.SqlBuilder{
|
||||||
{"tt.count", ">", "0", "int"},
|
{"tt.count", ">", "0", "int"},
|
||||||
{"tt.taxonomy", "in", ""},
|
{"tt.taxonomy", "in", ""},
|
||||||
}, "t.term_id", "", models.SqlBuilder{
|
}, "t.term_id", "", models.SqlBuilder{
|
||||||
|
@ -163,13 +163,13 @@ func categories(a ...any) (terms []wp.TermsMy, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func PasswordProjectTitle(post *wp.Posts) {
|
func PasswordProjectTitle(post *wp2.Posts) {
|
||||||
if post.PostPassword != "" {
|
if post.PostPassword != "" {
|
||||||
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
|
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func PasswdProjectContent(post *wp.Posts) {
|
func PasswdProjectContent(post *wp2.Posts) {
|
||||||
if post.PostContent != "" {
|
if post.PostContent != "" {
|
||||||
format := `
|
format := `
|
||||||
<form action="/login" class="post-password-form" method="post">
|
<form action="/login" class="post-password-form" method="post">
|
|
@ -4,9 +4,9 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/leeqvip/gophp"
|
"github.com/leeqvip/gophp"
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
wp2 "github/fthvgb1/wp-go/internal/wp"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/models"
|
"github/fthvgb1/wp-go/models"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -20,7 +20,7 @@ func GetPostMetaByPostId(ctx context.Context, id uint64) (r map[string]any, err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToPostThumbnail(c context.Context, postId uint64) (r wp.PostThumbnail) {
|
func ToPostThumbnail(c context.Context, postId uint64) (r wp2.PostThumbnail) {
|
||||||
meta, err := GetPostMetaByPostId(c, postId)
|
meta, err := GetPostMetaByPostId(c, postId)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
m, ok := meta["_thumbnail_id"]
|
m, ok := meta["_thumbnail_id"]
|
||||||
|
@ -64,7 +64,7 @@ func getPostMetaByPostIds(args ...any) (r map[uint64]map[string]any, err error)
|
||||||
r = make(map[uint64]map[string]any)
|
r = make(map[uint64]map[string]any)
|
||||||
ctx := args[0].(context.Context)
|
ctx := args[0].(context.Context)
|
||||||
ids := args[1].([]uint64)
|
ids := args[1].([]uint64)
|
||||||
rr, err := models.Find[wp.Postmeta](ctx, models.SqlBuilder{
|
rr, err := models.Find[wp2.Postmeta](ctx, models.SqlBuilder{
|
||||||
{"post_id", "in", ""},
|
{"post_id", "in", ""},
|
||||||
}, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64]))
|
}, "*", "", nil, nil, nil, 0, helper.SliceMap(ids, helper.ToAny[uint64]))
|
||||||
if err != nil {
|
if err != nil {
|
|
@ -6,9 +6,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
"github/fthvgb1/wp-go/internal/wp"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/models"
|
"github/fthvgb1/wp-go/models"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
|
@ -2,9 +2,9 @@ package common
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"github/fthvgb1/wp-go/internal/wp"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/models"
|
"github/fthvgb1/wp-go/models"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/actions/common"
|
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
common2 "github/fthvgb1/wp-go/internal/actions/common"
|
||||||
|
"github/fthvgb1/wp-go/internal/wp"
|
||||||
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"github/fthvgb1/wp-go/plugins"
|
"github/fthvgb1/wp-go/plugins"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -28,10 +28,10 @@ func Detail(c *gin.Context) {
|
||||||
hh := detailHandler{
|
hh := detailHandler{
|
||||||
c,
|
c,
|
||||||
}
|
}
|
||||||
recent := common.RecentPosts(c, 5)
|
recent := common2.RecentPosts(c, 5)
|
||||||
archive := common.Archives(c)
|
archive := common2.Archives(c)
|
||||||
categoryItems := common.Categories(c)
|
categoryItems := common2.Categories(c)
|
||||||
recentComments := common.RecentComments(c, 5)
|
recentComments := common2.RecentComments(c, 5)
|
||||||
var h = gin.H{
|
var h = gin.H{
|
||||||
"title": wpconfig.Options.Value("blogname"),
|
"title": wpconfig.Options.Value("blogname"),
|
||||||
"options": wpconfig.Options,
|
"options": wpconfig.Options,
|
||||||
|
@ -62,12 +62,12 @@ func Detail(c *gin.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ID := uint64(Id)
|
ID := uint64(Id)
|
||||||
maxId, err := common.GetMaxPostId(c)
|
maxId, err := common2.GetMaxPostId(c)
|
||||||
logs.ErrPrintln(err, "get max post id")
|
logs.ErrPrintln(err, "get max post id")
|
||||||
if ID > maxId || err != nil {
|
if ID > maxId || err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
post, err := common.GetPostById(c, ID)
|
post, err := common2.GetPostById(c, ID)
|
||||||
if post.Id == 0 || err != nil {
|
if post.Id == 0 || err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -76,10 +76,10 @@ func Detail(c *gin.Context) {
|
||||||
if post.CommentCount > 0 || post.CommentStatus == "open" {
|
if post.CommentCount > 0 || post.CommentStatus == "open" {
|
||||||
showComment = true
|
showComment = true
|
||||||
}
|
}
|
||||||
user := common.GetUserById(c, post.PostAuthor)
|
user := common2.GetUserById(c, post.PostAuthor)
|
||||||
common.PasswordProjectTitle(&post)
|
common2.PasswordProjectTitle(&post)
|
||||||
if post.PostPassword != "" && pw != post.PostPassword {
|
if post.PostPassword != "" && pw != post.PostPassword {
|
||||||
common.PasswdProjectContent(&post)
|
common2.PasswdProjectContent(&post)
|
||||||
showComment = false
|
showComment = false
|
||||||
} else if s, ok := commentCache.Get(c.Request.URL.RawQuery); ok && s != "" && (post.PostPassword == "" || post.PostPassword != "" && pw == post.PostPassword) {
|
} else if s, ok := commentCache.Get(c.Request.URL.RawQuery); ok && s != "" && (post.PostPassword == "" || post.PostPassword != "" && pw == post.PostPassword) {
|
||||||
c.Writer.WriteHeader(http.StatusOK)
|
c.Writer.WriteHeader(http.StatusOK)
|
||||||
|
@ -89,10 +89,10 @@ func Detail(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
plugins.ApplyPlugin(plugins.NewPostPlugin(c, plugins.Detail), &post)
|
plugins.ApplyPlugin(plugins.NewPostPlugin(c, plugins.Detail), &post)
|
||||||
comments, err := common.PostComments(c, post.Id)
|
comments, err := common2.PostComments(c, post.Id)
|
||||||
logs.ErrPrintln(err, "get post comment", post.Id)
|
logs.ErrPrintln(err, "get post comment", post.Id)
|
||||||
commentss := treeComments(comments)
|
commentss := treeComments(comments)
|
||||||
prev, next, err := common.GetContextPost(c, post.Id, post.PostDate)
|
prev, next, err := common2.GetContextPost(c, post.Id, post.PostDate)
|
||||||
logs.ErrPrintln(err, "get pre and next post", post.Id, post.PostDate)
|
logs.ErrPrintln(err, "get pre and next post", post.Id, post.PostDate)
|
||||||
h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wpconfig.Options.Value("blogname"))
|
h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wpconfig.Options.Value("blogname"))
|
||||||
h["post"] = post
|
h["post"] = post
|
|
@ -3,12 +3,12 @@ package actions
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/actions/common"
|
|
||||||
"github/fthvgb1/wp-go/cache"
|
"github/fthvgb1/wp-go/cache"
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
common2 "github/fthvgb1/wp-go/internal/actions/common"
|
||||||
|
wp2 "github/fthvgb1/wp-go/internal/wp"
|
||||||
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"github/fthvgb1/wp-go/plugins"
|
"github/fthvgb1/wp-go/plugins"
|
||||||
"github/fthvgb1/wp-go/rss2"
|
"github/fthvgb1/wp-go/rss2"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -77,21 +77,21 @@ func Feed(c *gin.Context) {
|
||||||
|
|
||||||
func feed(arg ...any) (xml []string, err error) {
|
func feed(arg ...any) (xml []string, err error) {
|
||||||
c := arg[0].(*gin.Context)
|
c := arg[0].(*gin.Context)
|
||||||
r := common.RecentPosts(c, 10)
|
r := common2.RecentPosts(c, 10)
|
||||||
ids := helper.SliceMap(r, func(t wp.Posts) uint64 {
|
ids := helper.SliceMap(r, func(t wp2.Posts) uint64 {
|
||||||
return t.Id
|
return t.Id
|
||||||
})
|
})
|
||||||
posts, err := common.GetPostsByIds(c, ids)
|
posts, err := common2.GetPostsByIds(c, ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rs := templateRss
|
rs := templateRss
|
||||||
rs.LastBuildDate = time.Now().Format(timeFormat)
|
rs.LastBuildDate = time.Now().Format(timeFormat)
|
||||||
rs.Items = helper.SliceMap(posts, func(t wp.Posts) rss2.Item {
|
rs.Items = helper.SliceMap(posts, func(t wp2.Posts) rss2.Item {
|
||||||
desc := "无法提供摘要。这是一篇受保护的文章。"
|
desc := "无法提供摘要。这是一篇受保护的文章。"
|
||||||
common.PasswordProjectTitle(&t)
|
common2.PasswordProjectTitle(&t)
|
||||||
if t.PostPassword != "" {
|
if t.PostPassword != "" {
|
||||||
common.PasswdProjectContent(&t)
|
common2.PasswdProjectContent(&t)
|
||||||
} else {
|
} else {
|
||||||
desc = plugins.DigestRaw(t.PostContent, 55, fmt.Sprintf("/p/%d", t.Id))
|
desc = plugins.DigestRaw(t.PostContent, 55, fmt.Sprintf("/p/%d", t.Id))
|
||||||
}
|
}
|
||||||
|
@ -101,7 +101,7 @@ func feed(arg ...any) (xml []string, err error) {
|
||||||
} else if t.CommentStatus == "open" && t.CommentCount == 0 {
|
} else if t.CommentStatus == "open" && t.CommentCount == 0 {
|
||||||
l = fmt.Sprintf("%s/p/%d#respond", wpconfig.Options.Value("siteurl"), t.Id)
|
l = fmt.Sprintf("%s/p/%d#respond", wpconfig.Options.Value("siteurl"), t.Id)
|
||||||
}
|
}
|
||||||
user := common.GetUserById(c, t.PostAuthor)
|
user := common2.GetUserById(c, t.PostAuthor)
|
||||||
|
|
||||||
return rss2.Item{
|
return rss2.Item{
|
||||||
Title: t.PostTitle,
|
Title: t.PostTitle,
|
||||||
|
@ -157,17 +157,17 @@ func postFeed(arg ...any) (x string, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ID := uint64(Id)
|
ID := uint64(Id)
|
||||||
maxId, err := common.GetMaxPostId(c)
|
maxId, err := common2.GetMaxPostId(c)
|
||||||
logs.ErrPrintln(err, "get max post id")
|
logs.ErrPrintln(err, "get max post id")
|
||||||
if ID > maxId || err != nil {
|
if ID > maxId || err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
post, err := common.GetPostById(c, ID)
|
post, err := common2.GetPostById(c, ID)
|
||||||
if post.Id == 0 || err != nil {
|
if post.Id == 0 || err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
common.PasswordProjectTitle(&post)
|
common2.PasswordProjectTitle(&post)
|
||||||
comments, err := common.PostComments(c, post.Id)
|
comments, err := common2.PostComments(c, post.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -179,7 +179,7 @@ func postFeed(arg ...any) (x string, err error) {
|
||||||
rs.LastBuildDate = time.Now().Format(timeFormat)
|
rs.LastBuildDate = time.Now().Format(timeFormat)
|
||||||
if post.PostPassword != "" {
|
if post.PostPassword != "" {
|
||||||
if len(comments) > 0 {
|
if len(comments) > 0 {
|
||||||
common.PasswdProjectContent(&post)
|
common2.PasswdProjectContent(&post)
|
||||||
t := comments[len(comments)-1]
|
t := comments[len(comments)-1]
|
||||||
rs.Items = []rss2.Item{
|
rs.Items = []rss2.Item{
|
||||||
{
|
{
|
||||||
|
@ -194,7 +194,7 @@ func postFeed(arg ...any) (x string, err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
rs.Items = helper.SliceMap(comments, func(t wp.Comments) rss2.Item {
|
rs.Items = helper.SliceMap(comments, func(t wp2.Comments) rss2.Item {
|
||||||
return rss2.Item{
|
return rss2.Item{
|
||||||
Title: fmt.Sprintf("评价者:%s", t.CommentAuthor),
|
Title: fmt.Sprintf("评价者:%s", t.CommentAuthor),
|
||||||
Link: fmt.Sprintf("%s/p/%d#comment-%d", wpconfig.Options.Value("siteurl"), post.Id, t.CommentId),
|
Link: fmt.Sprintf("%s/p/%d#comment-%d", wpconfig.Options.Value("siteurl"), post.Id, t.CommentId),
|
||||||
|
@ -227,24 +227,24 @@ func CommentsFeed(c *gin.Context) {
|
||||||
|
|
||||||
func commentsFeed(args ...any) (r []string, err error) {
|
func commentsFeed(args ...any) (r []string, err error) {
|
||||||
c := args[0].(*gin.Context)
|
c := args[0].(*gin.Context)
|
||||||
commens := common.RecentComments(c, 10)
|
commens := common2.RecentComments(c, 10)
|
||||||
rs := templateRss
|
rs := templateRss
|
||||||
rs.Title = fmt.Sprintf("\"%s\"的评论", wpconfig.Options.Value("blogname"))
|
rs.Title = fmt.Sprintf("\"%s\"的评论", wpconfig.Options.Value("blogname"))
|
||||||
rs.LastBuildDate = time.Now().Format(timeFormat)
|
rs.LastBuildDate = time.Now().Format(timeFormat)
|
||||||
rs.AtomLink = fmt.Sprintf("%s/comments/feed", wpconfig.Options.Value("siteurl"))
|
rs.AtomLink = fmt.Sprintf("%s/comments/feed", wpconfig.Options.Value("siteurl"))
|
||||||
com, err := common.GetCommentByIds(c, helper.SliceMap(commens, func(t wp.Comments) uint64 {
|
com, err := common2.GetCommentByIds(c, helper.SliceMap(commens, func(t wp2.Comments) uint64 {
|
||||||
return t.CommentId
|
return t.CommentId
|
||||||
}))
|
}))
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return []string{}, err
|
return []string{}, err
|
||||||
}
|
}
|
||||||
rs.Items = helper.SliceMap(com, func(t wp.Comments) rss2.Item {
|
rs.Items = helper.SliceMap(com, func(t wp2.Comments) rss2.Item {
|
||||||
post, _ := common.GetPostById(c, t.CommentPostId)
|
post, _ := common2.GetPostById(c, t.CommentPostId)
|
||||||
common.PasswordProjectTitle(&post)
|
common2.PasswordProjectTitle(&post)
|
||||||
desc := "评论受保护:要查看请输入密码。"
|
desc := "评论受保护:要查看请输入密码。"
|
||||||
content := t.CommentContent
|
content := t.CommentContent
|
||||||
if post.PostPassword != "" {
|
if post.PostPassword != "" {
|
||||||
common.PasswdProjectContent(&post)
|
common2.PasswdProjectContent(&post)
|
||||||
content = post.PostContent
|
content = post.PostContent
|
||||||
} else {
|
} else {
|
||||||
desc = plugins.ClearHtml(t.CommentContent)
|
desc = plugins.ClearHtml(t.CommentContent)
|
|
@ -4,11 +4,11 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/actions/common"
|
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
common2 "github/fthvgb1/wp-go/internal/actions/common"
|
||||||
|
"github/fthvgb1/wp-go/internal/wp"
|
||||||
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github/fthvgb1/wp-go/models"
|
"github/fthvgb1/wp-go/models"
|
||||||
"github/fthvgb1/wp-go/models/wp"
|
|
||||||
"github/fthvgb1/wp-go/plugins"
|
"github/fthvgb1/wp-go/plugins"
|
||||||
"math"
|
"math"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -113,7 +113,7 @@ func (h *indexHandle) parseParams() (err error) {
|
||||||
h.category = category
|
h.category = category
|
||||||
username := h.c.Param("author")
|
username := h.c.Param("author")
|
||||||
if username != "" {
|
if username != "" {
|
||||||
user, er := common.GetUserByName(h.c, username)
|
user, er := common2.GetUserByName(h.c, username)
|
||||||
if er != nil {
|
if er != nil {
|
||||||
err = er
|
err = er
|
||||||
return
|
return
|
||||||
|
@ -160,7 +160,7 @@ func (h *indexHandle) parseParams() (err error) {
|
||||||
h.page = pa
|
h.page = pa
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
total := int(atomic.LoadInt64(&common.TotalRaw))
|
total := int(atomic.LoadInt64(&common2.TotalRaw))
|
||||||
if total > 0 && total < (h.page-1)*h.pageSize {
|
if total > 0 && total < (h.page-1)*h.pageSize {
|
||||||
h.page = 1
|
h.page = 1
|
||||||
}
|
}
|
||||||
|
@ -180,10 +180,10 @@ func Index(c *gin.Context) {
|
||||||
var postIds []wp.Posts
|
var postIds []wp.Posts
|
||||||
var totalRaw int
|
var totalRaw int
|
||||||
var err error
|
var err error
|
||||||
archive := common.Archives(c)
|
archive := common2.Archives(c)
|
||||||
recent := common.RecentPosts(c, 5)
|
recent := common2.RecentPosts(c, 5)
|
||||||
categoryItems := common.Categories(c)
|
categoryItems := common2.Categories(c)
|
||||||
recentComments := common.RecentComments(c, 5)
|
recentComments := common2.RecentComments(c, 5)
|
||||||
ginH := gin.H{
|
ginH := gin.H{
|
||||||
"options": wpconfig.Options,
|
"options": wpconfig.Options,
|
||||||
"recentPosts": recent,
|
"recentPosts": recent,
|
||||||
|
@ -208,14 +208,14 @@ func Index(c *gin.Context) {
|
||||||
}
|
}
|
||||||
ginH["title"] = h.getTitle()
|
ginH["title"] = h.getTitle()
|
||||||
if c.Param("month") != "" {
|
if c.Param("month") != "" {
|
||||||
postIds, totalRaw, err = common.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order)
|
postIds, totalRaw, err = common2.GetMonthPostIds(c, c.Param("year"), c.Param("month"), h.page, h.pageSize, h.order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if h.search != "" {
|
} else if h.search != "" {
|
||||||
postIds, totalRaw, err = common.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
|
postIds, totalRaw, err = common2.SearchPost(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
|
||||||
} else {
|
} else {
|
||||||
postIds, totalRaw, err = common.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
|
postIds, totalRaw, err = common2.PostLists(c, h.getSearchKey(), c, h.where, h.page, h.pageSize, models.SqlBuilder{{h.orderBy, h.order}}, h.join, h.postType, h.status)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
|
@ -227,16 +227,16 @@ func Index(c *gin.Context) {
|
||||||
pw := h.session.Get("post_password")
|
pw := h.session.Get("post_password")
|
||||||
plug := plugins.NewPostPlugin(c, h.scene)
|
plug := plugins.NewPostPlugin(c, h.scene)
|
||||||
for i, post := range postIds {
|
for i, post := range postIds {
|
||||||
common.PasswordProjectTitle(&postIds[i])
|
common2.PasswordProjectTitle(&postIds[i])
|
||||||
if post.PostPassword != "" && pw != post.PostPassword {
|
if post.PostPassword != "" && pw != post.PostPassword {
|
||||||
common.PasswdProjectContent(&postIds[i])
|
common2.PasswdProjectContent(&postIds[i])
|
||||||
} else {
|
} else {
|
||||||
plugins.ApplyPlugin(plug, &postIds[i])
|
plugins.ApplyPlugin(plug, &postIds[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i, post := range recent {
|
for i, post := range recent {
|
||||||
if post.PostPassword != "" && pw != post.PostPassword {
|
if post.PostPassword != "" && pw != post.PostPassword {
|
||||||
common.PasswdProjectContent(&recent[i])
|
common2.PasswdProjectContent(&recent[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
q := c.Request.URL.Query().Encode()
|
q := c.Request.URL.Query().Encode()
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
|
||||||
"github/fthvgb1/wp-go/helper"
|
"github/fthvgb1/wp-go/helper"
|
||||||
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github/fthvgb1/wp-go/phpass"
|
"github/fthvgb1/wp-go/phpass"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
|
@ -5,7 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/config"
|
"github/fthvgb1/wp-go/config"
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"github/fthvgb1/wp-go/logs"
|
"github/fthvgb1/wp-go/logs"
|
||||||
"github/fthvgb1/wp-go/mail"
|
"github/fthvgb1/wp-go/mail"
|
||||||
"io"
|
"io"
|
|
@ -6,12 +6,12 @@ import (
|
||||||
"github.com/gin-contrib/sessions"
|
"github.com/gin-contrib/sessions"
|
||||||
"github.com/gin-contrib/sessions/cookie"
|
"github.com/gin-contrib/sessions/cookie"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github/fthvgb1/wp-go/actions"
|
|
||||||
"github/fthvgb1/wp-go/config"
|
"github/fthvgb1/wp-go/config"
|
||||||
"github/fthvgb1/wp-go/config/wpconfig"
|
actions2 "github/fthvgb1/wp-go/internal/actions"
|
||||||
"github/fthvgb1/wp-go/middleware"
|
middleware2 "github/fthvgb1/wp-go/internal/middleware"
|
||||||
"github/fthvgb1/wp-go/static"
|
"github/fthvgb1/wp-go/internal/static"
|
||||||
"github/fthvgb1/wp-go/templates"
|
"github/fthvgb1/wp-go/internal/templates"
|
||||||
|
"github/fthvgb1/wp-go/internal/wpconfig"
|
||||||
"html/template"
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
@ -40,14 +40,14 @@ func SetupRouter() (*gin.Engine, func()) {
|
||||||
return wpconfig.Options.Value(k)
|
return wpconfig.Options.Value(k)
|
||||||
},
|
},
|
||||||
}).SetTemplate()
|
}).SetTemplate()
|
||||||
validServerName, reloadValidServerNameFn := middleware.ValidateServerNames()
|
validServerName, reloadValidServerNameFn := middleware2.ValidateServerNames()
|
||||||
fl, flReload := middleware.FlowLimit(c.MaxRequestSleepNum, c.MaxRequestNum, c.SleepTime)
|
fl, flReload := middleware2.FlowLimit(c.MaxRequestSleepNum, c.MaxRequestNum, c.SleepTime)
|
||||||
r.Use(
|
r.Use(
|
||||||
gin.Logger(),
|
gin.Logger(),
|
||||||
validServerName,
|
validServerName,
|
||||||
middleware.RecoverAndSendMail(gin.DefaultErrorWriter),
|
middleware2.RecoverAndSendMail(gin.DefaultErrorWriter),
|
||||||
fl,
|
fl,
|
||||||
middleware.SetStaticFileCache,
|
middleware2.SetStaticFileCache,
|
||||||
)
|
)
|
||||||
//gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用
|
//gzip 因为一般会用nginx做反代时自动使用gzip,所以go这边本身可以不用
|
||||||
if c.Gzip {
|
if c.Gzip {
|
||||||
|
@ -65,24 +65,24 @@ func SetupRouter() (*gin.Engine, func()) {
|
||||||
}))
|
}))
|
||||||
store := cookie.NewStore([]byte("secret"))
|
store := cookie.NewStore([]byte("secret"))
|
||||||
r.Use(sessions.Sessions("go-wp", store))
|
r.Use(sessions.Sessions("go-wp", store))
|
||||||
sl, slRload := middleware.SearchLimit(c.SingleIpSearchNum)
|
sl, slRload := middleware2.SearchLimit(c.SingleIpSearchNum)
|
||||||
r.GET("/", sl, actions.Index)
|
r.GET("/", sl, actions2.Index)
|
||||||
r.GET("/page/:page", actions.Index)
|
r.GET("/page/:page", actions2.Index)
|
||||||
r.GET("/p/category/:category", actions.Index)
|
r.GET("/p/category/:category", actions2.Index)
|
||||||
r.GET("/p/category/:category/page/:page", actions.Index)
|
r.GET("/p/category/:category/page/:page", actions2.Index)
|
||||||
r.GET("/p/tag/:tag", actions.Index)
|
r.GET("/p/tag/:tag", actions2.Index)
|
||||||
r.GET("/p/tag/:tag/page/:page", actions.Index)
|
r.GET("/p/tag/:tag/page/:page", actions2.Index)
|
||||||
r.GET("/p/date/:year/:month", actions.Index)
|
r.GET("/p/date/:year/:month", actions2.Index)
|
||||||
r.GET("/p/date/:year/:month/page/:page", actions.Index)
|
r.GET("/p/date/:year/:month/page/:page", actions2.Index)
|
||||||
r.GET("/p/author/:author", actions.Index)
|
r.GET("/p/author/:author", actions2.Index)
|
||||||
r.GET("/p/author/:author/page/:page", actions.Index)
|
r.GET("/p/author/:author/page/:page", actions2.Index)
|
||||||
r.POST("/login", actions.Login)
|
r.POST("/login", actions2.Login)
|
||||||
r.GET("/p/:id", actions.Detail)
|
r.GET("/p/:id", actions2.Detail)
|
||||||
r.GET("/p/:id/feed", actions.PostFeed)
|
r.GET("/p/:id/feed", actions2.PostFeed)
|
||||||
r.GET("/feed", actions.Feed)
|
r.GET("/feed", actions2.Feed)
|
||||||
r.GET("/comments/feed", actions.CommentsFeed)
|
r.GET("/comments/feed", actions2.CommentsFeed)
|
||||||
cfl, _ := middleware.FlowLimit(c.MaxRequestSleepNum, 5, c.SleepTime)
|
cfl, _ := middleware2.FlowLimit(c.MaxRequestSleepNum, 5, c.SleepTime)
|
||||||
r.POST("/comment", cfl, actions.PostComment)
|
r.POST("/comment", cfl, actions2.PostComment)
|
||||||
if gin.Mode() != gin.ReleaseMode {
|
if gin.Mode() != gin.ReleaseMode {
|
||||||
pprof.Register(r, "dev/pprof")
|
pprof.Register(r, "dev/pprof")
|
||||||
}
|
}
|
Before Width: | Height: | Size: 7.0 KiB After Width: | Height: | Size: 7.0 KiB |
Before Width: | Height: | Size: 322 KiB After Width: | Height: | Size: 322 KiB |
Before Width: | Height: | Size: 256 KiB After Width: | Height: | Size: 256 KiB |
Before Width: | Height: | Size: 134 KiB After Width: | Height: | Size: 134 KiB |
Before Width: | Height: | Size: 77 KiB After Width: | Height: | Size: 77 KiB |
|
@ -27,7 +27,7 @@
|
||||||
@media screen and (-webkit-min-device-pixel-ratio:0) {
|
@media screen and (-webkit-min-device-pixel-ratio:0) {
|
||||||
@font-face {
|
@font-face {
|
||||||
font-family: "Genericons";
|
font-family: "Genericons";
|
||||||
src: url("./Genericons.svg#Genericons") format("svg");
|
src: url("Genericons.svg#Genericons") format("svg");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|