目录调整

This commit is contained in:
xing 2022-11-05 10:32:57 +08:00
parent 4f58d86a59
commit fc5e71d79d
21 changed files with 137 additions and 129 deletions

View File

@ -9,7 +9,7 @@ import (
"github/fthvgb1/wp-go/config" "github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/logs" "github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/mail" "github/fthvgb1/wp-go/mail"
"github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp"
"io" "io"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
@ -68,7 +68,7 @@ func PostComment(c *gin.Context) {
logs.ErrPrintln(err, "获取文档", id) logs.ErrPrintln(err, "获取文档", id)
return return
} }
su := fmt.Sprintf("%s: %s[%s]发表了评论对文档[%v]的评论", models.Options["siteurl"], author, m, post.PostTitle) su := fmt.Sprintf("%s: %s[%s]发表了评论对文档[%v]的评论", wp.Options["siteurl"], author, m, post.PostTitle)
err = mail.SendMail([]string{config.Conf.Mail.User}, su, comment) err = mail.SendMail([]string{config.Conf.Mail.User}, su, comment)
logs.ErrPrintln(err, "发送邮件") logs.ErrPrintln(err, "发送邮件")
}() }()

View File

@ -5,11 +5,12 @@ import (
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"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"
) )
func RecentComments(ctx context.Context, n int) (r []models.WpComments) { func RecentComments(ctx context.Context, n int) (r []wp.WpComments) {
r, err := recentCommentsCaches.GetCache(ctx, time.Second) r, err := recentCommentsCaches.GetCache(ctx, time.Second)
if len(r) > n { if len(r) > n {
r = r[0:n] r = r[0:n]
@ -17,8 +18,8 @@ func RecentComments(ctx context.Context, n int) (r []models.WpComments) {
logs.ErrPrintln(err, "get recent comment") logs.ErrPrintln(err, "get recent comment")
return return
} }
func recentComments(...any) (r []models.WpComments, err error) { func recentComments(...any) (r []wp.WpComments, err error) {
return models.Find[models.WpComments](models.SqlBuilder{ return models.Find[wp.WpComments](models.SqlBuilder{
{"comment_approved", "1"}, {"comment_approved", "1"},
{"post_status", "publish"}, {"post_status", "publish"},
}, "comment_ID,comment_author,comment_post_ID,post_title", "", models.SqlBuilder{{"comment_date_gmt", "desc"}}, models.SqlBuilder{ }, "comment_ID,comment_author,comment_post_ID,post_title", "", models.SqlBuilder{{"comment_date_gmt", "desc"}}, models.SqlBuilder{
@ -26,7 +27,7 @@ func recentComments(...any) (r []models.WpComments, err error) {
}, nil, 10) }, nil, 10)
} }
func PostComments(ctx context.Context, Id uint64) ([]models.WpComments, error) { func PostComments(ctx context.Context, Id uint64) ([]wp.WpComments, error) {
ids, err := postCommentCaches.GetCache(ctx, Id, time.Second, Id) ids, err := postCommentCaches.GetCache(ctx, Id, time.Second, Id)
if err != nil { if err != nil {
return nil, err return nil, err
@ -36,7 +37,7 @@ func PostComments(ctx context.Context, Id uint64) ([]models.WpComments, error) {
func postComments(args ...any) ([]uint64, error) { func postComments(args ...any) ([]uint64, error) {
postId := args[0].(uint64) postId := args[0].(uint64)
r, err := models.Find[models.WpComments](models.SqlBuilder{ r, err := models.Find[wp.WpComments](models.SqlBuilder{
{"comment_approved", "1"}, {"comment_approved", "1"},
{"comment_post_ID", "=", strconv.FormatUint(postId, 10), "int"}, {"comment_post_ID", "=", strconv.FormatUint(postId, 10), "int"},
}, "comment_ID", "", models.SqlBuilder{ }, "comment_ID", "", models.SqlBuilder{
@ -46,29 +47,29 @@ func postComments(args ...any) ([]uint64, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return helper.SliceMap(r, func(t models.WpComments) uint64 { return helper.SliceMap(r, func(t wp.WpComments) uint64 {
return t.CommentId return t.CommentId
}), err }), err
} }
func GetCommentById(ctx context.Context, id uint64) (models.WpComments, error) { func GetCommentById(ctx context.Context, id uint64) (wp.WpComments, error) {
return commentsCache.GetCache(ctx, id, time.Second, id) return commentsCache.GetCache(ctx, id, time.Second, id)
} }
func GetCommentByIds(ctx context.Context, ids []uint64) ([]models.WpComments, error) { func GetCommentByIds(ctx context.Context, ids []uint64) ([]wp.WpComments, error) {
return commentsCache.GetCacheBatch(ctx, ids, time.Second, ids) return commentsCache.GetCacheBatch(ctx, ids, time.Second, ids)
} }
func getCommentByIds(args ...any) (map[uint64]models.WpComments, error) { func getCommentByIds(args ...any) (map[uint64]wp.WpComments, error) {
ids := args[0].([]uint64) ids := args[0].([]uint64)
m := make(map[uint64]models.WpComments) m := make(map[uint64]wp.WpComments)
r, err := models.SimpleFind[models.WpComments](models.SqlBuilder{ r, err := models.SimpleFind[wp.WpComments](models.SqlBuilder{
{"comment_ID", "in", ""}, {"comment_approved", "1"}, {"comment_ID", "in", ""}, {"comment_approved", "1"},
}, "*", helper.SliceMap(ids, helper.ToAny[uint64])) }, "*", helper.SliceMap(ids, helper.ToAny[uint64]))
if err != nil { if err != nil {
return m, err return m, err
} }
return helper.SimpleSliceToMap(r, func(t models.WpComments) uint64 { return helper.SimpleSliceToMap(r, func(t wp.WpComments) uint64 {
return t.CommentId return t.CommentId
}), err }), err
} }

View File

@ -7,24 +7,25 @@ import (
"github/fthvgb1/wp-go/config" "github/fthvgb1/wp-go/config"
"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[models.WpTermsMy] var categoryCaches *cache.SliceCache[wp.WpTermsMy]
var recentPostsCaches *cache.SliceCache[models.WpPosts] var recentPostsCaches *cache.SliceCache[wp.WpPosts]
var recentCommentsCaches *cache.SliceCache[models.WpComments] var recentCommentsCaches *cache.SliceCache[wp.WpComments]
var postCommentCaches *cache.MapCache[uint64, []uint64] var postCommentCaches *cache.MapCache[uint64, []uint64]
var postsCache *cache.MapCache[uint64, models.WpPosts] var postsCache *cache.MapCache[uint64, wp.WpPosts]
var monthPostsCache *cache.MapCache[string, []uint64] var monthPostsCache *cache.MapCache[string, []uint64]
var postListIdsCache *cache.MapCache[string, PostIds] 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 int var TotalRaw int
var usersCache *cache.MapCache[uint64, models.WpUsers] var usersCache *cache.MapCache[uint64, wp.WpUsers]
var commentsCache *cache.MapCache[uint64, models.WpComments] var commentsCache *cache.MapCache[uint64, wp.WpComments]
func InitActionsCommonCache() { func InitActionsCommonCache() {
archivesCaches = &Arch{ archivesCaches = &Arch{
@ -40,21 +41,21 @@ func InitActionsCommonCache() {
postContextCache = cache.NewMapCacheByFn[uint64, PostContext](getPostContext, config.Conf.ContextPostCacheTime) postContextCache = cache.NewMapCacheByFn[uint64, PostContext](getPostContext, config.Conf.ContextPostCacheTime)
postsCache = cache.NewMapCacheByBatchFn[uint64, models.WpPosts](getPostsByIds, config.Conf.PostDataCacheTime) postsCache = cache.NewMapCacheByBatchFn[uint64, wp.WpPosts](getPostsByIds, config.Conf.PostDataCacheTime)
categoryCaches = cache.NewSliceCache[models.WpTermsMy](categories, config.Conf.CategoryCacheTime) categoryCaches = cache.NewSliceCache[wp.WpTermsMy](categories, config.Conf.CategoryCacheTime)
recentPostsCaches = cache.NewSliceCache[models.WpPosts](recentPosts, config.Conf.RecentPostCacheTime) recentPostsCaches = cache.NewSliceCache[wp.WpPosts](recentPosts, config.Conf.RecentPostCacheTime)
recentCommentsCaches = cache.NewSliceCache[models.WpComments](recentComments, config.Conf.RecentCommentsCacheTime) recentCommentsCaches = cache.NewSliceCache[wp.WpComments](recentComments, config.Conf.RecentCommentsCacheTime)
postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, config.Conf.PostCommentsCacheTime) postCommentCaches = cache.NewMapCacheByFn[uint64, []uint64](postComments, config.Conf.PostCommentsCacheTime)
maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, config.Conf.MaxPostIdCacheTime) maxPostIdCache = cache.NewSliceCache[uint64](getMaxPostId, config.Conf.MaxPostIdCacheTime)
usersCache = cache.NewMapCacheByBatchFn[uint64, models.WpUsers](getUsers, config.Conf.UserInfoCacheTime) usersCache = cache.NewMapCacheByBatchFn[uint64, wp.WpUsers](getUsers, config.Conf.UserInfoCacheTime)
commentsCache = cache.NewMapCacheByBatchFn[uint64, models.WpComments](getCommentByIds, config.Conf.CommentsCacheTime) commentsCache = cache.NewMapCacheByBatchFn[uint64, wp.WpComments](getCommentByIds, config.Conf.CommentsCacheTime)
} }
func ClearCache() { func ClearCache() {
@ -74,13 +75,13 @@ type PostIds struct {
} }
type Arch struct { type Arch struct {
data []models.PostArchive data []wp.PostArchive
mutex *sync.Mutex mutex *sync.Mutex
setCacheFunc func() ([]models.PostArchive, error) setCacheFunc func() ([]wp.PostArchive, error)
month time.Month month time.Month
} }
func (c *Arch) getArchiveCache() []models.PostArchive { func (c *Arch) getArchiveCache() []wp.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 {
@ -98,29 +99,29 @@ func (c *Arch) getArchiveCache() []models.PostArchive {
} }
type PostContext struct { type PostContext struct {
prev models.WpPosts prev wp.WpPosts
next models.WpPosts next wp.WpPosts
} }
func archives() ([]models.PostArchive, error) { func archives() ([]wp.PostArchive, error) {
return models.Find[models.PostArchive](models.SqlBuilder{ return models.Find[wp.PostArchive](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() (r []models.PostArchive) { func Archives() (r []wp.PostArchive) {
return archivesCaches.getArchiveCache() return archivesCaches.getArchiveCache()
} }
func Categories(ctx context.Context) []models.WpTermsMy { func Categories(ctx context.Context) []wp.WpTermsMy {
r, err := categoryCaches.GetCache(ctx, time.Second) r, err := categoryCaches.GetCache(ctx, time.Second)
logs.ErrPrintln(err, "get category ") logs.ErrPrintln(err, "get category ")
return r return r
} }
func categories(...any) (terms []models.WpTermsMy, err error) { func categories(...any) (terms []wp.WpTermsMy, err error) {
var in = []any{"category"} var in = []any{"category"}
terms, err = models.Find[models.WpTermsMy](models.SqlBuilder{ terms, err = models.Find[wp.WpTermsMy](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{
@ -129,23 +130,23 @@ func categories(...any) (terms []models.WpTermsMy, err error) {
{"t", "inner join", "wp_term_taxonomy tt", "t.term_id = tt.term_id"}, {"t", "inner join", "wp_term_taxonomy tt", "t.term_id = tt.term_id"},
}, nil, 0, in) }, nil, 0, in)
for i := 0; i < len(terms); i++ { for i := 0; i < len(terms); i++ {
if v, ok := models.Terms[terms[i].WpTerms.TermId]; ok { if v, ok := wp.Terms[terms[i].WpTerms.TermId]; ok {
terms[i].WpTerms = v terms[i].WpTerms = v
} }
if v, ok := models.TermTaxonomy[terms[i].WpTerms.TermId]; ok { if v, ok := wp.TermTaxonomy[terms[i].WpTerms.TermId]; ok {
terms[i].WpTermTaxonomy = v terms[i].WpTermTaxonomy = v
} }
} }
return return
} }
func PasswordProjectTitle(post *models.WpPosts) { func PasswordProjectTitle(post *wp.WpPosts) {
if post.PostPassword != "" { if post.PostPassword != "" {
post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle) post.PostTitle = fmt.Sprintf("密码保护:%s", post.PostTitle)
} }
} }
func PasswdProjectContent(post *models.WpPosts) { func PasswdProjectContent(post *wp.WpPosts) {
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">

View File

@ -8,19 +8,20 @@ import (
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"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"
"time" "time"
) )
func GetPostById(ctx context.Context, id uint64) (models.WpPosts, error) { func GetPostById(ctx context.Context, id uint64) (wp.WpPosts, error) {
return postsCache.GetCache(ctx, id, time.Second, id) return postsCache.GetCache(ctx, id, time.Second, id)
} }
func GetPostsByIds(ctx context.Context, ids []uint64) ([]models.WpPosts, error) { func GetPostsByIds(ctx context.Context, ids []uint64) ([]wp.WpPosts, error) {
return postsCache.GetCacheBatch(ctx, ids, time.Second, ids) return postsCache.GetCacheBatch(ctx, ids, time.Second, ids)
} }
func SearchPost(ctx context.Context, key string, args ...any) (r []models.WpPosts, total int, err error) { func SearchPost(ctx context.Context, key string, args ...any) (r []wp.WpPosts, total int, err error) {
ids, err := searchPostIdsCache.GetCache(ctx, key, time.Second, args...) ids, err := searchPostIdsCache.GetCache(ctx, key, time.Second, args...)
if err != nil { if err != nil {
return return
@ -30,11 +31,11 @@ func SearchPost(ctx context.Context, key string, args ...any) (r []models.WpPost
return return
} }
func getPostsByIds(ids ...any) (m map[uint64]models.WpPosts, err error) { func getPostsByIds(ids ...any) (m map[uint64]wp.WpPosts, err error) {
m = make(map[uint64]models.WpPosts) m = make(map[uint64]wp.WpPosts)
id := ids[0].([]uint64) id := ids[0].([]uint64)
arg := helper.SliceMap(id, helper.ToAny[uint64]) arg := helper.SliceMap(id, helper.ToAny[uint64])
rawPosts, err := models.Find[models.WpPosts](models.SqlBuilder{{ rawPosts, err := models.Find[wp.WpPosts](models.SqlBuilder{{
"Id", "in", "", "Id", "in", "",
}}, "a.*,ifnull(d.name,'') category_name,ifnull(taxonomy,'') `taxonomy`", "", nil, models.SqlBuilder{{ }}, "a.*,ifnull(d.name,'') category_name,ifnull(taxonomy,'') `taxonomy`", "", nil, models.SqlBuilder{{
"a", "left join", "wp_term_relationships b", "a.Id=b.object_id", "a", "left join", "wp_term_relationships b", "a.Id=b.object_id",
@ -46,7 +47,7 @@ func getPostsByIds(ids ...any) (m map[uint64]models.WpPosts, err error) {
if err != nil { if err != nil {
return m, err return m, err
} }
postsMap := make(map[uint64]models.WpPosts) postsMap := make(map[uint64]wp.WpPosts)
for i, post := range rawPosts { for i, post := range rawPosts {
v, ok := postsMap[post.Id] v, ok := postsMap[post.Id]
if !ok { if !ok {
@ -79,7 +80,7 @@ func getPostsByIds(ids ...any) (m map[uint64]models.WpPosts, err error) {
return return
} }
func PostLists(ctx context.Context, key string, args ...any) (r []models.WpPosts, total int, err error) { func PostLists(ctx context.Context, key string, args ...any) (r []wp.WpPosts, total int, err error) {
ids, err := postListIdsCache.GetCache(ctx, key, time.Second, args...) ids, err := postListIdsCache.GetCache(ctx, key, time.Second, args...)
if err != nil { if err != nil {
return return
@ -97,7 +98,7 @@ func searchPostIds(args ...any) (ids PostIds, err error) {
join := args[4].(models.SqlBuilder) join := args[4].(models.SqlBuilder)
postType := args[5].([]any) postType := args[5].([]any)
postStatus := args[6].([]any) postStatus := args[6].([]any)
res, total, err := models.SimplePagination[models.WpPosts](where, "ID", "", page, limit, order, join, nil, postType, postStatus) res, total, err := models.SimplePagination[wp.WpPosts](where, "ID", "", page, limit, order, join, nil, postType, postStatus)
for _, posts := range res { for _, posts := range res {
ids.Ids = append(ids.Ids, posts.Id) ids.Ids = append(ids.Ids, posts.Id)
} }
@ -109,7 +110,7 @@ func searchPostIds(args ...any) (ids PostIds, err error) {
} }
func getMaxPostId(...any) ([]uint64, error) { func getMaxPostId(...any) ([]uint64, error) {
r, err := models.SimpleFind[models.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID") r, err := models.SimpleFind[wp.WpPosts](models.SqlBuilder{{"post_type", "post"}, {"post_status", "publish"}}, "max(ID) ID")
var id uint64 var id uint64
if len(r) > 0 { if len(r) > 0 {
id = r[0].Id id = r[0].Id
@ -122,7 +123,7 @@ func GetMaxPostId(ctx *gin.Context) (uint64, error) {
return Id[0], err return Id[0], err
} }
func RecentPosts(ctx context.Context, n int) (r []models.WpPosts) { func RecentPosts(ctx context.Context, n int) (r []wp.WpPosts) {
r, err := recentPostsCaches.GetCache(ctx, time.Second) r, err := recentPostsCaches.GetCache(ctx, time.Second)
if n < len(r) { if n < len(r) {
r = r[:n] r = r[:n]
@ -130,8 +131,8 @@ func RecentPosts(ctx context.Context, n int) (r []models.WpPosts) {
logs.ErrPrintln(err, "get recent post") logs.ErrPrintln(err, "get recent post")
return return
} }
func recentPosts(...any) (r []models.WpPosts, err error) { func recentPosts(...any) (r []wp.WpPosts, err error) {
r, err = models.Find[models.WpPosts](models.SqlBuilder{{ r, err = models.Find[wp.WpPosts](models.SqlBuilder{{
"post_type", "post", "post_type", "post",
}, {"post_status", "publish"}}, "ID,post_title,post_password", "", models.SqlBuilder{{"post_date", "desc"}}, nil, nil, 10) }, {"post_status", "publish"}}, "ID,post_title,post_password", "", models.SqlBuilder{{"post_date", "desc"}}, nil, nil, 10)
for i, post := range r { for i, post := range r {
@ -142,10 +143,10 @@ func recentPosts(...any) (r []models.WpPosts, err error) {
return return
} }
func GetContextPost(ctx context.Context, id uint64, date time.Time) (prev, next models.WpPosts, err error) { func GetContextPost(ctx context.Context, id uint64, date time.Time) (prev, next wp.WpPosts, err error) {
postCtx, err := postContextCache.GetCache(ctx, id, time.Second, date) postCtx, err := postContextCache.GetCache(ctx, id, time.Second, date)
if err != nil { if err != nil {
return models.WpPosts{}, models.WpPosts{}, err return wp.WpPosts{}, wp.WpPosts{}, err
} }
prev = postCtx.prev prev = postCtx.prev
next = postCtx.next next = postCtx.next
@ -154,7 +155,7 @@ func GetContextPost(ctx context.Context, id uint64, date time.Time) (prev, next
func getPostContext(arg ...any) (r PostContext, err error) { func getPostContext(arg ...any) (r PostContext, err error) {
t := arg[0].(time.Time) t := arg[0].(time.Time)
next, err := models.FirstOne[models.WpPosts](models.SqlBuilder{ next, err := models.FirstOne[wp.WpPosts](models.SqlBuilder{
{"post_date", ">", t.Format("2006-01-02 15:04:05")}, {"post_date", ">", t.Format("2006-01-02 15:04:05")},
{"post_status", "in", ""}, {"post_status", "in", ""},
{"post_type", "post"}, {"post_type", "post"},
@ -165,7 +166,7 @@ func getPostContext(arg ...any) (r PostContext, err error) {
if err != nil { if err != nil {
return return
} }
prev, err := models.FirstOne[models.WpPosts](models.SqlBuilder{ prev, err := models.FirstOne[wp.WpPosts](models.SqlBuilder{
{"post_date", "<", t.Format("2006-01-02 15:04:05")}, {"post_date", "<", t.Format("2006-01-02 15:04:05")},
{"post_status", "in", ""}, {"post_status", "in", ""},
{"post_type", "post"}, {"post_type", "post"},
@ -183,7 +184,7 @@ func getPostContext(arg ...any) (r PostContext, err error) {
return return
} }
func GetMonthPostIds(ctx context.Context, year, month string, page, limit int, order string) (r []models.WpPosts, total int, err error) { func GetMonthPostIds(ctx context.Context, year, month string, page, limit int, order string) (r []wp.WpPosts, total int, err error) {
res, err := monthPostsCache.GetCache(ctx, fmt.Sprintf("%s%s", year, month), time.Second, year, month) res, err := monthPostsCache.GetCache(ctx, fmt.Sprintf("%s%s", year, month), time.Second, year, month)
if err != nil { if err != nil {
return return
@ -207,7 +208,7 @@ func monthPost(args ...any) (r []uint64, err error) {
} }
postType := []any{"post"} postType := []any{"post"}
status := []any{"publish"} status := []any{"publish"}
ids, err := models.Find[models.WpPosts](where, "ID", "", models.SqlBuilder{{"Id", "asc"}}, nil, nil, 0, postType, status) ids, err := models.Find[wp.WpPosts](where, "ID", "", models.SqlBuilder{{"Id", "asc"}}, nil, nil, 0, postType, status)
if err != nil { if err != nil {
return return
} }

View File

@ -4,19 +4,20 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"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"
) )
func getUsers(...any) (m map[uint64]models.WpUsers, err error) { func getUsers(...any) (m map[uint64]wp.WpUsers, err error) {
m = make(map[uint64]models.WpUsers) m = make(map[uint64]wp.WpUsers)
r, err := models.SimpleFind[models.WpUsers](nil, "*") r, err := models.SimpleFind[wp.WpUsers](nil, "*")
for _, user := range r { for _, user := range r {
m[user.Id] = user m[user.Id] = user
} }
return return
} }
func GetUser(ctx *gin.Context, uid uint64) models.WpUsers { func GetUser(ctx *gin.Context, uid uint64) wp.WpUsers {
r, err := usersCache.GetCache(ctx, uid, time.Second, uid) r, err := usersCache.GetCache(ctx, uid, time.Second, uid)
logs.ErrPrintln(err, "get user", uid) logs.ErrPrintln(err, "get user", uid)
return r return r

View File

@ -7,7 +7,7 @@ import (
"github/fthvgb1/wp-go/actions/common" "github/fthvgb1/wp-go/actions/common"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/logs" "github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/plugins" "github/fthvgb1/wp-go/plugins"
"math/rand" "math/rand"
"net/http" "net/http"
@ -32,8 +32,8 @@ func Detail(c *gin.Context) {
categoryItems := common.Categories(c) categoryItems := common.Categories(c)
recentComments := common.RecentComments(c, 5) recentComments := common.RecentComments(c, 5)
var h = gin.H{ var h = gin.H{
"title": models.Options["blogname"], "title": wp.Options["blogname"],
"options": models.Options, "options": wp.Options,
"recentPosts": recent, "recentPosts": recent,
"archives": archive, "archives": archive,
"categories": categoryItems, "categories": categoryItems,
@ -81,11 +81,11 @@ func Detail(c *gin.Context) {
commentss := treeComments(comments) commentss := treeComments(comments)
prev, next, err := common.GetContextPost(c, post.Id, post.PostDate) prev, next, err := common.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, models.Options["blogname"]) h["title"] = fmt.Sprintf("%s-%s", post.PostTitle, wp.Options["blogname"])
h["post"] = post h["post"] = post
h["showComment"] = showComment h["showComment"] = showComment
h["prev"] = prev h["prev"] = prev
depth := models.Options["thread_comments_depth"] depth := wp.Options["thread_comments_depth"]
d, err := strconv.Atoi(depth) d, err := strconv.Atoi(depth)
if err != nil { if err != nil {
logs.ErrPrintln(err, "get comment depth") logs.ErrPrintln(err, "get comment depth")
@ -96,7 +96,7 @@ func Detail(c *gin.Context) {
} }
type Comment struct { type Comment struct {
models.WpComments wp.WpComments
Children []*Comment Children []*Comment
} }
@ -163,10 +163,10 @@ func findComments(comments Comments) Comments {
return r return r
} }
func treeComments(comments []models.WpComments) Comments { func treeComments(comments []wp.WpComments) Comments {
var r = map[uint64]*Comment{ var r = map[uint64]*Comment{
0: { 0: {
WpComments: models.WpComments{}, WpComments: wp.WpComments{},
}, },
} }
var top []*Comment var top []*Comment
@ -190,7 +190,7 @@ func treeComments(comments []models.WpComments) Comments {
return top return top
} }
func (d detailHandler) formatLi(comments models.WpComments, depth int, eo, parent string) string { func (d detailHandler) formatLi(comments wp.WpComments, depth int, eo, parent string) string {
li := ` li := `
<li id="comment-{{CommentId}}" class="comment {{eo}} thread-even depth-{{Depth}} {{parent}}"> <li id="comment-{{CommentId}}" class="comment {{eo}} thread-even depth-{{Depth}} {{parent}}">
<article id="div-comment-{{CommentId}}" class="comment-body"> <article id="div-comment-{{CommentId}}" class="comment-body">
@ -262,7 +262,7 @@ func gravatar(c *gin.Context, email string) (u string) {
q := url.Values{} q := url.Values{}
q.Add("s", "112") q.Add("s", "112")
q.Add("d", "mm") q.Add("d", "mm")
q.Add("r", "g") q.Add("r", strings.ToLower(wp.Options["avatar_rating"]))
u = fmt.Sprintf("%s?%s", u, q.Encode()) u = fmt.Sprintf("%s?%s", u, q.Encode())
return return
} }

View File

@ -7,7 +7,7 @@ import (
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/logs" "github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/models" "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"
@ -25,14 +25,14 @@ var commentsFeedCache = cache.NewSliceCache(commentsFeed, time.Hour)
func InitFeed() { func InitFeed() {
templateRss = rss2.Rss2{ templateRss = rss2.Rss2{
Title: models.Options["blogname"], Title: wp.Options["blogname"],
AtomLink: fmt.Sprintf("%s/feed", models.Options["home"]), AtomLink: fmt.Sprintf("%s/feed", wp.Options["home"]),
Link: models.Options["siteurl"], Link: wp.Options["siteurl"],
Description: models.Options["blogdescription"], Description: wp.Options["blogdescription"],
Language: "zh-CN", Language: "zh-CN",
UpdatePeriod: "hourly", UpdatePeriod: "hourly",
UpdateFrequency: 1, UpdateFrequency: 1,
Generator: models.Options["home"], Generator: wp.Options["home"],
} }
} }
@ -72,7 +72,7 @@ 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 := common.RecentPosts(c, 10)
ids := helper.SliceMap(r, func(t models.WpPosts) uint64 { ids := helper.SliceMap(r, func(t wp.WpPosts) uint64 {
return t.Id return t.Id
}) })
posts, err := common.GetPostsByIds(c, ids) posts, err := common.GetPostsByIds(c, ids)
@ -81,7 +81,7 @@ func feed(arg ...any) (xml []string, err error) {
} }
rs := templateRss rs := templateRss
rs.LastBuildDate = time.Now().Format(timeFormat) rs.LastBuildDate = time.Now().Format(timeFormat)
rs.Items = helper.SliceMap(posts, func(t models.WpPosts) rss2.Item { rs.Items = helper.SliceMap(posts, func(t wp.WpPosts) rss2.Item {
desc := "无法提供摘要。这是一篇受保护的文章。" desc := "无法提供摘要。这是一篇受保护的文章。"
common.PasswordProjectTitle(&t) common.PasswordProjectTitle(&t)
if t.PostPassword != "" { if t.PostPassword != "" {
@ -91,9 +91,9 @@ func feed(arg ...any) (xml []string, err error) {
} }
l := "" l := ""
if t.CommentStatus == "open" && t.CommentCount > 0 { if t.CommentStatus == "open" && t.CommentCount > 0 {
l = fmt.Sprintf("%s/p/%d#comments", models.Options["siteurl"], t.Id) l = fmt.Sprintf("%s/p/%d#comments", wp.Options["siteurl"], t.Id)
} else if t.CommentStatus == "open" && t.CommentCount == 0 { } else if t.CommentStatus == "open" && t.CommentCount == 0 {
l = fmt.Sprintf("%s/p/%d#respond", models.Options["siteurl"], t.Id) l = fmt.Sprintf("%s/p/%d#respond", wp.Options["siteurl"], t.Id)
} }
user := common.GetUser(c, t.PostAuthor) user := common.GetUser(c, t.PostAuthor)
@ -105,8 +105,8 @@ func feed(arg ...any) (xml []string, err error) {
Content: t.PostContent, Content: t.PostContent,
Category: strings.Join(t.Categories, "、"), Category: strings.Join(t.Categories, "、"),
CommentLink: l, CommentLink: l,
CommentRss: fmt.Sprintf("%s/p/%d/feed", models.Options["siteurl"], t.Id), CommentRss: fmt.Sprintf("%s/p/%d/feed", wp.Options["siteurl"], t.Id),
Link: fmt.Sprintf("%s/p/%d", models.Options["siteurl"], t.Id), Link: fmt.Sprintf("%s/p/%d", wp.Options["siteurl"], t.Id),
Description: desc, Description: desc,
PubDate: t.PostDateGmt.Format(timeFormat), PubDate: t.PostDateGmt.Format(timeFormat),
} }
@ -168,8 +168,8 @@ func postFeed(arg ...any) (x string, err error) {
rs := templateRss rs := templateRss
rs.Title = fmt.Sprintf("《%s》的评论", post.PostTitle) rs.Title = fmt.Sprintf("《%s》的评论", post.PostTitle)
rs.AtomLink = fmt.Sprintf("%s/p/%d/feed", models.Options["siteurl"], post.Id) rs.AtomLink = fmt.Sprintf("%s/p/%d/feed", wp.Options["siteurl"], post.Id)
rs.Link = fmt.Sprintf("%s/p/%d", models.Options["siteurl"], post.Id) rs.Link = fmt.Sprintf("%s/p/%d", wp.Options["siteurl"], post.Id)
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 {
@ -178,7 +178,7 @@ func postFeed(arg ...any) (x string, err error) {
rs.Items = []rss2.Item{ rs.Items = []rss2.Item{
{ {
Title: fmt.Sprintf("评价者:%s", t.CommentAuthor), Title: fmt.Sprintf("评价者:%s", t.CommentAuthor),
Link: fmt.Sprintf("%s/p/%d#comment-%d", models.Options["siteurl"], post.Id, t.CommentId), Link: fmt.Sprintf("%s/p/%d#comment-%d", wp.Options["siteurl"], post.Id, t.CommentId),
Creator: t.CommentAuthor, Creator: t.CommentAuthor,
PubDate: t.CommentDateGmt.Format(timeFormat), PubDate: t.CommentDateGmt.Format(timeFormat),
Guid: fmt.Sprintf("%s#comment-%d", post.Guid, t.CommentId), Guid: fmt.Sprintf("%s#comment-%d", post.Guid, t.CommentId),
@ -188,10 +188,10 @@ func postFeed(arg ...any) (x string, err error) {
} }
} }
} else { } else {
rs.Items = helper.SliceMap(comments, func(t models.WpComments) rss2.Item { rs.Items = helper.SliceMap(comments, func(t wp.WpComments) 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", models.Options["siteurl"], post.Id, t.CommentId), Link: fmt.Sprintf("%s/p/%d#comment-%d", wp.Options["siteurl"], post.Id, t.CommentId),
Creator: t.CommentAuthor, Creator: t.CommentAuthor,
PubDate: t.CommentDateGmt.Format(timeFormat), PubDate: t.CommentDateGmt.Format(timeFormat),
Guid: fmt.Sprintf("%s#comment-%d", post.Guid, t.CommentId), Guid: fmt.Sprintf("%s#comment-%d", post.Guid, t.CommentId),
@ -223,16 +223,16 @@ func commentsFeed(args ...any) (r []string, err error) {
c := args[0].(*gin.Context) c := args[0].(*gin.Context)
commens := common.RecentComments(c, 10) commens := common.RecentComments(c, 10)
rs := templateRss rs := templateRss
rs.Title = fmt.Sprintf("\"%s\"的评论", models.Options["blogname"]) rs.Title = fmt.Sprintf("\"%s\"的评论", wp.Options["blogname"])
rs.LastBuildDate = time.Now().Format(timeFormat) rs.LastBuildDate = time.Now().Format(timeFormat)
rs.AtomLink = fmt.Sprintf("%s/comments/feed", models.Options["siteurl"]) rs.AtomLink = fmt.Sprintf("%s/comments/feed", wp.Options["siteurl"])
com, err := common.GetCommentByIds(c, helper.SliceMap(commens, func(t models.WpComments) uint64 { com, err := common.GetCommentByIds(c, helper.SliceMap(commens, func(t wp.WpComments) 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 models.WpComments) rss2.Item { rs.Items = helper.SliceMap(com, func(t wp.WpComments) rss2.Item {
post, _ := common.GetPostById(c, t.CommentPostId) post, _ := common.GetPostById(c, t.CommentPostId)
common.PasswordProjectTitle(&post) common.PasswordProjectTitle(&post)
desc := "评论受保护:要查看请输入密码。" desc := "评论受保护:要查看请输入密码。"
@ -246,7 +246,7 @@ func commentsFeed(args ...any) (r []string, err error) {
} }
return rss2.Item{ return rss2.Item{
Title: fmt.Sprintf("%s对《%s》的评论", t.CommentAuthor, post.PostTitle), Title: fmt.Sprintf("%s对《%s》的评论", t.CommentAuthor, post.PostTitle),
Link: fmt.Sprintf("%s/p/%d#comment-%d", models.Options["siteurl"], post.Id, t.CommentId), Link: fmt.Sprintf("%s/p/%d#comment-%d", wp.Options["siteurl"], post.Id, t.CommentId),
Creator: t.CommentAuthor, Creator: t.CommentAuthor,
Description: desc, Description: desc,
PubDate: t.CommentDateGmt.Format(timeFormat), PubDate: t.CommentDateGmt.Format(timeFormat),

View File

@ -7,6 +7,7 @@ import (
"github/fthvgb1/wp-go/actions/common" "github/fthvgb1/wp-go/actions/common"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"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"
@ -39,7 +40,7 @@ type indexHandle struct {
} }
func newIndexHandle(ctx *gin.Context) *indexHandle { func newIndexHandle(ctx *gin.Context) *indexHandle {
size := models.Options["posts_per_page"] size := wp.Options["posts_per_page"]
si, _ := strconv.Atoi(size) si, _ := strconv.Atoi(size)
return &indexHandle{ return &indexHandle{
c: ctx, c: ctx,
@ -47,8 +48,8 @@ func newIndexHandle(ctx *gin.Context) *indexHandle {
page: 1, page: 1,
pageSize: si, pageSize: si,
paginationStep: 1, paginationStep: 1,
titleL: models.Options["blogname"], titleL: wp.Options["blogname"],
titleR: models.Options["blogdescription"], titleR: wp.Options["blogdescription"],
where: models.SqlBuilder{ where: models.SqlBuilder{
{"post_type", "in", ""}, {"post_type", "in", ""},
{"post_status", "in", ""}, {"post_status", "in", ""},
@ -92,7 +93,7 @@ func (h *indexHandle) parseParams() {
}) })
ss := fmt.Sprintf("%s年%s月", year, strings.TrimLeft(month, "0")) ss := fmt.Sprintf("%s年%s月", year, strings.TrimLeft(month, "0"))
h.header = fmt.Sprintf("月度归档: <span>%s</span>", ss) h.header = fmt.Sprintf("月度归档: <span>%s</span>", ss)
h.setTitleLR(ss, models.Options["blogname"]) h.setTitleLR(ss, wp.Options["blogname"])
h.scene = plugins.Archive h.scene = plugins.Archive
} }
category := h.c.Param("category") category := h.c.Param("category")
@ -119,7 +120,7 @@ func (h *indexHandle) parseParams() {
}, []string{ }, []string{
"left join", "wp_terms d", "c.term_id=d.term_id", "left join", "wp_terms d", "c.term_id=d.term_id",
}) })
h.setTitleLR(category, models.Options["blogname"]) h.setTitleLR(category, wp.Options["blogname"])
h.scene = plugins.Category h.scene = plugins.Category
} }
s := h.c.Query("s") s := h.c.Query("s")
@ -132,7 +133,7 @@ func (h *indexHandle) parseParams() {
}, []string{"post_password", ""}) }, []string{"post_password", ""})
h.postType = append(h.postType, "page", "attachment") h.postType = append(h.postType, "page", "attachment")
h.header = fmt.Sprintf("%s的搜索结果", s) h.header = fmt.Sprintf("%s的搜索结果", s)
h.setTitleLR(helper.StrJoin(`"`, s, `"`, "的搜索结果"), models.Options["blogname"]) h.setTitleLR(helper.StrJoin(`"`, s, `"`, "的搜索结果"), wp.Options["blogname"])
h.search = s h.search = s
h.scene = plugins.Search h.scene = plugins.Search
} }
@ -149,7 +150,7 @@ func (h *indexHandle) parseParams() {
h.page = 1 h.page = 1
} }
if h.page > 1 && (h.category != "" || h.search != "" || month != "") { if h.page > 1 && (h.category != "" || h.search != "" || month != "") {
h.setTitleLR(fmt.Sprintf("%s-第%d页", h.titleL, h.page), models.Options["blogname"]) h.setTitleLR(fmt.Sprintf("%s-第%d页", h.titleL, h.page), wp.Options["blogname"])
} }
} }
@ -166,7 +167,7 @@ func Index(c *gin.Context) {
categoryItems := common.Categories(c) categoryItems := common.Categories(c)
recentComments := common.RecentComments(c, 5) recentComments := common.RecentComments(c, 5)
ginH := gin.H{ ginH := gin.H{
"options": models.Options, "options": wp.Options,
"recentPosts": recent, "recentPosts": recent,
"archives": archive, "archives": archive,
"categories": categoryItems, "categories": categoryItems,
@ -175,7 +176,7 @@ func Index(c *gin.Context) {
"title": h.getTitle(), "title": h.getTitle(),
"recentComments": recentComments, "recentComments": recentComments,
} }
var postIds []models.WpPosts var postIds []wp.WpPosts
var totalRaw int var totalRaw int
var err error var err error
if c.Param("month") != "" { if c.Param("month") != "" {

View File

@ -5,7 +5,7 @@ import (
"github.com/gin-contrib/sessions" "github.com/gin-contrib/sessions"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/phpass" "github/fthvgb1/wp-go/phpass"
"net/http" "net/http"
"strings" "strings"
@ -33,7 +33,7 @@ func Login(c *gin.Context) {
c.Error(err) c.Error(err)
return return
} }
cohash := fmt.Sprintf("wp-postpass_%s", helper.StringMd5(models.Options["siteurl"])) cohash := fmt.Sprintf("wp-postpass_%s", helper.StringMd5(wp.Options["siteurl"]))
c.SetCookie(cohash, pass, 24*3600, "/", "", false, false) c.SetCookie(cohash, pass, 24*3600, "/", "", false, false)
c.Redirect(http.StatusFound, ref) c.Redirect(http.StatusFound, ref)

View File

@ -5,7 +5,7 @@ import (
"github/fthvgb1/wp-go/actions/common" "github/fthvgb1/wp-go/actions/common"
"github/fthvgb1/wp-go/config" "github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/db" "github/fthvgb1/wp-go/db"
"github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp"
"github/fthvgb1/wp-go/plugins" "github/fthvgb1/wp-go/plugins"
"github/fthvgb1/wp-go/route" "github/fthvgb1/wp-go/route"
"math/rand" "math/rand"
@ -24,12 +24,12 @@ func init() {
panic(err) panic(err)
} }
err = models.InitOptions() err = wp.InitOptions()
if err != nil { if err != nil {
panic(err) panic(err)
} }
err = models.InitTerms() err = wp.InitTerms()
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -7,7 +7,7 @@ import (
"github/fthvgb1/wp-go/config" "github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/logs" "github/fthvgb1/wp-go/logs"
"github/fthvgb1/wp-go/mail" "github/fthvgb1/wp-go/mail"
"github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp"
"io" "io"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
@ -43,7 +43,7 @@ func RecoverAndSendMail(w io.Writer) func(ctx *gin.Context) {
er := mail.SendMail( er := mail.SendMail(
[]string{config.Conf.Mail.User}, []string{config.Conf.Mail.User},
fmt.Sprintf("%s%s %s 发生错误", fmt.Sprintf(models.Options["siteurl"]), c.FullPath(), time.Now().Format(time.RFC1123Z)), content) fmt.Sprintf("%s%s %s 发生错误", fmt.Sprintf(wp.Options["siteurl"]), c.FullPath(), time.Now().Format(time.RFC1123Z)), content)
if er != nil { if er != nil {
logs.ErrPrintln(er, "recover send mail fail", fmt.Sprintf("%v", err)) logs.ErrPrintln(er, "recover send mail fail", fmt.Sprintf("%v", err))

View File

@ -1,16 +1,18 @@
package models package wp
import "github/fthvgb1/wp-go/models"
var Options = make(map[string]string) var Options = make(map[string]string)
var Terms = map[uint64]WpTerms{} var Terms = map[uint64]WpTerms{}
var TermTaxonomy = map[uint64]WpTermTaxonomy{} var TermTaxonomy = map[uint64]WpTermTaxonomy{}
func InitOptions() error { func InitOptions() error {
ops, err := SimpleFind[WpOptions](SqlBuilder{{"autoload", "yes"}}, "option_name, option_value") ops, err := models.SimpleFind[WpOptions](models.SqlBuilder{{"autoload", "yes"}}, "option_name, option_value")
if err != nil { if err != nil {
return err return err
} }
if len(ops) == 0 { if len(ops) == 0 {
ops, err = SimpleFind[WpOptions](nil, "option_name, option_value") ops, err = models.SimpleFind[WpOptions](nil, "option_name, option_value")
if err != nil { if err != nil {
return err return err
} }
@ -22,14 +24,14 @@ func InitOptions() error {
} }
func InitTerms() (err error) { func InitTerms() (err error) {
terms, err := SimpleFind[WpTerms](nil, "*") terms, err := models.SimpleFind[WpTerms](nil, "*")
if err != nil { if err != nil {
return err return err
} }
for _, wpTerms := range terms { for _, wpTerms := range terms {
Terms[wpTerms.TermId] = wpTerms Terms[wpTerms.TermId] = wpTerms
} }
termTax, err := SimpleFind[WpTermTaxonomy](nil, "*") termTax, err := models.SimpleFind[WpTermTaxonomy](nil, "*")
if err != nil { if err != nil {
return err return err
} }

View File

@ -1,4 +1,4 @@
package models package wp
import "time" import "time"

View File

@ -1,4 +1,4 @@
package models package wp
type WpOptions struct { type WpOptions struct {
OptionId uint64 `gorm:"column:option_id" db:"option_id" json:"option_id" form:"option_id"` OptionId uint64 `gorm:"column:option_id" db:"option_id" json:"option_id" form:"option_id"`

View File

@ -1,4 +1,4 @@
package models package wp
import "time" import "time"

View File

@ -1,4 +1,4 @@
package models package wp
type WpTermTaxonomy struct { type WpTermTaxonomy struct {
TermTaxonomyId uint64 `gorm:"column:term_taxonomy_id" db:"term_taxonomy_id" json:"term_taxonomy_id" form:"term_taxonomy_id"` TermTaxonomyId uint64 `gorm:"column:term_taxonomy_id" db:"term_taxonomy_id" json:"term_taxonomy_id" form:"term_taxonomy_id"`

View File

@ -1,4 +1,4 @@
package models package wp
type WpTerms struct { type WpTerms struct {
TermId uint64 `gorm:"column:term_id" db:"term_id" json:"term_id" form:"term_id"` TermId uint64 `gorm:"column:term_id" db:"term_id" json:"term_id" form:"term_id"`

View File

@ -1,4 +1,4 @@
package models package wp
import "time" import "time"

View File

@ -13,6 +13,7 @@ import (
"unicode/utf8" "unicode/utf8"
) )
// PasswordHash 目前还不完善只有encode64 getRandomBytes CryptPrivate 方法能用
type PasswordHash struct { type PasswordHash struct {
itoa64 string itoa64 string
iterationCountLog2 int iterationCountLog2 int

View File

@ -6,7 +6,7 @@ import (
"github/fthvgb1/wp-go/cache" "github/fthvgb1/wp-go/cache"
"github/fthvgb1/wp-go/config" "github/fthvgb1/wp-go/config"
"github/fthvgb1/wp-go/helper" "github/fthvgb1/wp-go/helper"
"github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp"
"regexp" "regexp"
"strings" "strings"
"time" "time"
@ -116,7 +116,7 @@ func DigestRaw(str string, limit int, u string) string {
return content return content
} }
func Digest(p *Plugin[models.WpPosts], c *gin.Context, post *models.WpPosts, scene uint) { func Digest(p *Plugin[wp.WpPosts], c *gin.Context, post *wp.WpPosts, scene uint) {
if scene == Detail { if scene == Detail {
return return
} }

View File

@ -2,16 +2,16 @@ package plugins
import ( import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github/fthvgb1/wp-go/models" "github/fthvgb1/wp-go/models/wp"
) )
func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[models.WpPosts] { func NewPostPlugin(ctx *gin.Context, scene uint) *Plugin[wp.WpPosts] {
p := NewPlugin[models.WpPosts](nil, -1, nil, scene, ctx) p := NewPlugin[wp.WpPosts](nil, -1, nil, scene, ctx)
p.Push(Digest) p.Push(Digest)
return p return p
} }
func ApplyPlugin(p *Plugin[models.WpPosts], post *models.WpPosts) { func ApplyPlugin(p *Plugin[wp.WpPosts], post *wp.WpPosts) {
p.post = post p.post = post
p.Next() p.Next()
p.index = -1 p.index = -1