Compare commits
No commits in common. "ae6e496dd8ade29ab96c0f6775a150038b898da9" and "448d6a6baf23b6165a84b73bd9aee2a3728efa41" have entirely different histories.
ae6e496dd8
...
448d6a6baf
|
@ -9,7 +9,6 @@ import (
|
|||
"github.com/fthvgb1/wp-go/app/static"
|
||||
"github.com/fthvgb1/wp-go/app/theme"
|
||||
"github.com/fthvgb1/wp-go/app/wpconfig"
|
||||
str "github.com/fthvgb1/wp-go/helper/strings"
|
||||
"github.com/gin-contrib/gzip"
|
||||
"github.com/gin-contrib/pprof"
|
||||
"github.com/gin-contrib/sessions"
|
||||
|
@ -55,14 +54,6 @@ func SetupRouter() *gin.Engine {
|
|||
}
|
||||
|
||||
f := static.Fs{FS: static.FsDir, Path: "wp-includes"}
|
||||
if c.WpDir != "" {
|
||||
r.Static("/wp-content/uploads", str.Join(c.WpDir, "/wp-content/uploads"))
|
||||
r.Static("/wp-content/themes", str.Join(c.WpDir, "/wp-content/themes"))
|
||||
r.Static("/wp-content/plugins", str.Join(c.WpDir, "/wp-content/plugins"))
|
||||
r.Static("/wp-includes/css", str.Join(c.WpDir, "/wp-includes/css"))
|
||||
r.Static("/wp-includes/fonts", str.Join(c.WpDir, "/wp-includes/fonts"))
|
||||
r.Static("/wp-includes/js", str.Join(c.WpDir, "/wp-includes/js"))
|
||||
} else {
|
||||
r.StaticFileFS("/favicon.ico", "favicon.ico", http.FS(static.FsDir))
|
||||
r.StaticFS("/wp-includes", http.FS(f))
|
||||
r.StaticFS("/wp-content/plugins", http.FS(static.Fs{
|
||||
|
@ -76,8 +67,6 @@ func SetupRouter() *gin.Engine {
|
|||
if c.UploadDir != "" {
|
||||
r.Static("/wp-content/uploads", c.UploadDir)
|
||||
}
|
||||
}
|
||||
|
||||
store := cookie.NewStore([]byte("secret"))
|
||||
r.Use(sessions.Sessions("go-wp", store))
|
||||
r.GET("/", middleware.SearchLimit(c.SingleIpSearchNum), actions.ThemeHook(constraints.Home))
|
||||
|
|
|
@ -4,8 +4,6 @@ import (
|
|||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/app/pkg/config"
|
||||
"github.com/gin-gonic/gin"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -18,11 +16,6 @@ var path = map[string]struct{}{
|
|||
func SetStaticFileCache(c *gin.Context) {
|
||||
f := strings.Split(strings.TrimLeft(c.FullPath(), "/"), "/")
|
||||
if _, ok := path[f[0]]; ok {
|
||||
if ".php" == filepath.Ext(c.Request.URL.Path) {
|
||||
c.Abort()
|
||||
c.Status(http.StatusForbidden)
|
||||
return
|
||||
}
|
||||
t := config.GetConfig().CacheTime.CacheControl
|
||||
if t > 0 {
|
||||
c.Header("Cache-Control", fmt.Sprintf("private, max-age=%d", int(t.Seconds())))
|
||||
|
|
|
@ -1,16 +1,10 @@
|
|||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/fthvgb1/wp-go/safety"
|
||||
"gopkg.in/yaml.v2"
|
||||
"io"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -45,7 +39,6 @@ type Config struct {
|
|||
ShowQuerySql bool `yaml:"showQuerySql" json:"showQuerySql,omitempty"`
|
||||
Plugins []string `yaml:"plugins" json:"plugins,omitempty"`
|
||||
LogOutput string `yaml:"logOutput" json:"logOutput,omitempty"`
|
||||
WpDir string `yaml:"wpDir" json:"wpDir"`
|
||||
}
|
||||
|
||||
type CacheTime struct {
|
||||
|
@ -91,39 +84,12 @@ func InitConfig(conf string) error {
|
|||
if conf == "" {
|
||||
conf = "config.yaml"
|
||||
}
|
||||
var file []byte
|
||||
var err error
|
||||
if strings.Contains(conf, "http") {
|
||||
get, err := http.Get(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
file, err = io.ReadAll(get.Body)
|
||||
} else {
|
||||
file, err = os.ReadFile(conf)
|
||||
}
|
||||
file, err := os.ReadFile(conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var c Config
|
||||
switch strings.ToLower(filepath.Ext(conf)) {
|
||||
case ".yaml":
|
||||
err = yaml.Unmarshal(file, &c)
|
||||
case ".json":
|
||||
err = json.Unmarshal(file, &c)
|
||||
default:
|
||||
err = yaml.Unmarshal(file, &c)
|
||||
if err != nil {
|
||||
err = json.Unmarshal(file, &c)
|
||||
if err == nil {
|
||||
break
|
||||
}
|
||||
} else {
|
||||
break
|
||||
}
|
||||
return errors.New("invalid suffix config file")
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -88,8 +88,6 @@ trustServerNames: ["xy.test","blog.xy.test"]
|
|||
theme: "twentyfifteen"
|
||||
# 文档排序默认升序还是降序
|
||||
postOrder: "desc"
|
||||
# WordPress path
|
||||
wpDir: "/var/www/wordpress"
|
||||
# 上传的目录
|
||||
uploadDir: ""
|
||||
# pprof route path 为空表示不开启pprof,否则为pprof的路由
|
||||
|
|
|
@ -42,7 +42,7 @@ type post struct {
|
|||
PostMeta *[]models.PostMeta
|
||||
TermTaxonomy *[]TermTaxonomy
|
||||
Terms *[]models.Terms
|
||||
CommentMetas []CommentMeta
|
||||
CommentMetas *[]CommentMeta
|
||||
}
|
||||
|
||||
type TermRelationships struct {
|
||||
|
|
|
@ -24,7 +24,7 @@ const (
|
|||
|
||||
// Relationship join table
|
||||
//
|
||||
// RelationType HasOne| HasMany
|
||||
// # RelationType HasOne| HasMany
|
||||
//
|
||||
// eg: hasOne, post has a user. ForeignKey is user's id , Local is post's userId field
|
||||
//
|
||||
|
|
|
@ -175,7 +175,7 @@ var postHaveManyCommentMetas = func() RelationFn {
|
|||
v := slice.Map(*i, func(t metas) CommentMeta {
|
||||
return t.CommentMeta
|
||||
})
|
||||
m.CommentMetas = v
|
||||
m.CommentMetas = &v
|
||||
}, Relationship{
|
||||
RelationType: HasOne,
|
||||
Table: "wp_commentmeta",
|
||||
|
|
Loading…
Reference in New Issue
Block a user