完善状态码
This commit is contained in:
parent
23f32c8fed
commit
bfd4e4ac4d
|
@ -4,7 +4,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
"github.com/fthvgb1/wp-go/internal/pkg/cache"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
"github.com/fthvgb1/wp-go/internal/pkg/logs"
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||||
"github.com/fthvgb1/wp-go/internal/plugins"
|
"github.com/fthvgb1/wp-go/internal/plugins"
|
||||||
|
@ -26,7 +25,6 @@ func (d *DetailHandle) BuildDetailData() (err error) {
|
||||||
d.GinH["title"] = wpconfig.Options.Value("blogname")
|
d.GinH["title"] = wpconfig.Options.Value("blogname")
|
||||||
err = d.CheckAndGetPost()
|
err = d.CheckAndGetPost()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Scene = constraints.Error404
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
d.WidgetAreaData()
|
d.WidgetAreaData()
|
||||||
|
@ -41,12 +39,10 @@ func (d *DetailHandle) CheckAndGetPost() (err error) {
|
||||||
maxId, err := cache.GetMaxPostId(d.C)
|
maxId, err := cache.GetMaxPostId(d.C)
|
||||||
logs.ErrPrintln(err, "get max post id")
|
logs.ErrPrintln(err, "get max post id")
|
||||||
if id > maxId || id <= 0 || err != nil {
|
if id > maxId || id <= 0 || err != nil {
|
||||||
d.Stats = constraints.Error404
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
post, err := cache.GetPostById(d.C, id)
|
post, err := cache.GetPostById(d.C, id)
|
||||||
if post.Id == 0 || err != nil || post.PostStatus != "publish" {
|
if post.Id == 0 || err != nil || post.PostStatus != "publish" {
|
||||||
d.Stats = constraints.Error404
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
"github.com/fthvgb1/wp-go/internal/pkg/models"
|
||||||
"github.com/fthvgb1/wp-go/model"
|
"github.com/fthvgb1/wp-go/model"
|
||||||
"github.com/fthvgb1/wp-go/plugin/pagination"
|
"github.com/fthvgb1/wp-go/plugin/pagination"
|
||||||
"net/http"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) {
|
func (i *IndexHandle) ParseIndex(parm *IndexParams) (err error) {
|
||||||
|
@ -76,14 +75,10 @@ func (i *IndexHandle) Pagination() {
|
||||||
func (i *IndexHandle) BuildIndexData(parm *IndexParams) (err error) {
|
func (i *IndexHandle) BuildIndexData(parm *IndexParams) (err error) {
|
||||||
err = i.ParseIndex(parm)
|
err = i.ParseIndex(parm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
i.Stats = constraints.ParamError
|
|
||||||
i.Code = http.StatusNotFound
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
posts, totalRows, err := i.GetIndexData()
|
posts, totalRows, err := i.GetIndexData()
|
||||||
if err != nil && err != sql.ErrNoRows {
|
if err != nil && err != sql.ErrNoRows {
|
||||||
i.Scene = constraints.InternalErr
|
|
||||||
i.Code = http.StatusInternalServerError
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i.GinH["posts"] = posts
|
i.GinH["posts"] = posts
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
"github.com/fthvgb1/wp-go/internal/pkg/constraints"
|
||||||
"github.com/fthvgb1/wp-go/internal/plugins"
|
"github.com/fthvgb1/wp-go/internal/plugins"
|
||||||
"github.com/fthvgb1/wp-go/internal/theme/common"
|
"github.com/fthvgb1/wp-go/internal/theme/common"
|
||||||
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
const ThemeName = "twentyfifteen"
|
const ThemeName = "twentyfifteen"
|
||||||
|
@ -39,6 +40,8 @@ func (i *indexHandle) Index() {
|
||||||
|
|
||||||
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
i.Stats = constraints.Error404
|
||||||
|
i.Code = http.StatusNotFound
|
||||||
i.C.HTML(i.Code, i.Templ, i.GinH)
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -54,6 +57,7 @@ func (d *detailHandle) Detail() {
|
||||||
err := d.BuildDetailData()
|
err := d.BuildDetailData()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Stats = constraints.Error404
|
d.Stats = constraints.Error404
|
||||||
|
d.Code = http.StatusNotFound
|
||||||
d.C.HTML(d.Code, d.Templ, d.GinH)
|
d.C.HTML(d.Code, d.Templ, d.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,27 +73,31 @@ var pluginFns = func() map[string]common.Plugin[models.Posts] {
|
||||||
|
|
||||||
func (i *indexHandle) Index() {
|
func (i *indexHandle) Index() {
|
||||||
i.Templ = "twentyseventeen/posts/index.gohtml"
|
i.Templ = "twentyseventeen/posts/index.gohtml"
|
||||||
p := common.NewIndexParams(i.C)
|
err := i.BuildIndexData(common.NewIndexParams(i.C))
|
||||||
err := i.BuildIndexData(p)
|
|
||||||
i.GinH["bodyClass"] = i.h.bodyClass()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
i.Stats = constraints.Error404
|
||||||
|
i.Code = http.StatusNotFound
|
||||||
|
i.GinH["bodyClass"] = i.h.bodyClass()
|
||||||
i.C.HTML(i.Code, i.Templ, i.GinH)
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
i.PageEle = paginate
|
i.PageEle = paginate
|
||||||
i.ExecListPagePlugin(pluginFns)
|
i.ExecListPagePlugin(pluginFns)
|
||||||
i.Pagination()
|
i.Pagination()
|
||||||
|
i.GinH["bodyClass"] = i.h.bodyClass()
|
||||||
i.C.HTML(i.Code, i.Templ, i.GinH)
|
i.C.HTML(i.Code, i.Templ, i.GinH)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *detailHandle) Detail() {
|
func (d *detailHandle) Detail() {
|
||||||
err := d.BuildDetailData()
|
err := d.BuildDetailData()
|
||||||
d.GinH["bodyClass"] = d.h.bodyClass()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
d.Code = http.StatusNotFound
|
d.Code = http.StatusNotFound
|
||||||
|
d.Stats = constraints.Error404
|
||||||
|
d.GinH["bodyClass"] = d.h.bodyClass()
|
||||||
d.C.HTML(d.Code, d.Templ, d.GinH)
|
d.C.HTML(d.Code, d.Templ, d.GinH)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
d.GinH["bodyClass"] = d.h.bodyClass()
|
||||||
img := plugins.Thumbnail(d.Post.Thumbnail.OriginAttachmentData, "thumbnail", "", "thumbnail", "post-thumbnail")
|
img := plugins.Thumbnail(d.Post.Thumbnail.OriginAttachmentData, "thumbnail", "", "thumbnail", "post-thumbnail")
|
||||||
img.Width = img.OriginAttachmentData.Width
|
img.Width = img.OriginAttachmentData.Width
|
||||||
img.Height = img.OriginAttachmentData.Height
|
img.Height = img.OriginAttachmentData.Height
|
||||||
|
|
Loading…
Reference in New Issue
Block a user