This commit is contained in:
@@ -2,6 +2,8 @@ package http
|
||||
|
||||
import (
|
||||
"context"
|
||||
"mime"
|
||||
"path/filepath"
|
||||
|
||||
"quyun/v2/app/commands"
|
||||
"quyun/v2/app/errorx"
|
||||
@@ -21,7 +23,9 @@ import (
|
||||
"go.ipao.vip/atom/container"
|
||||
"go.ipao.vip/atom/contracts"
|
||||
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/favicon"
|
||||
"github.com/rogeecn/fabfile"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"go.uber.org/dig"
|
||||
@@ -86,6 +90,38 @@ func Serve(cmd *cobra.Command, args []string) error {
|
||||
route.Register(group)
|
||||
}
|
||||
|
||||
svc.Http.Engine.Get("/admin*", checkStaticFile(svc.App.DistAdmin))
|
||||
svc.Http.Engine.Get("/*", checkStaticFile(svc.App.DistWeChat))
|
||||
|
||||
return svc.Http.Serve(ctx)
|
||||
})
|
||||
}
|
||||
|
||||
func checkStaticFile(rootPath string) func(ctx fiber.Ctx) error {
|
||||
return func(ctx fiber.Ctx) error {
|
||||
f := ctx.Params("*")
|
||||
if f == "/" || f == "" {
|
||||
f = "index.html"
|
||||
}
|
||||
|
||||
checkFiles := []string{f, "index.html"}
|
||||
for _, checkFile := range checkFiles {
|
||||
filePath := filepath.Join(rootPath, checkFile)
|
||||
log.Infof("check file: %s", filePath)
|
||||
file, err := fabfile.Find(filePath)
|
||||
if err != nil {
|
||||
log.Warnf("file not found: %s", filePath)
|
||||
continue
|
||||
}
|
||||
|
||||
ext := filepath.Ext(filePath)
|
||||
mime := mime.TypeByExtension(ext)
|
||||
|
||||
log.Infof("mime type: %s %s", ext, mime)
|
||||
ctx.Set(fiber.HeaderContentType, mime)
|
||||
|
||||
return ctx.SendFile(file)
|
||||
}
|
||||
return ctx.SendStatus(fiber.StatusNotFound)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ import (
|
||||
|
||||
type PostListQuery struct {
|
||||
*requests.Pagination
|
||||
Keyword *string `query:"keyword"`
|
||||
Status fields.PostStatus `query:"status"`
|
||||
Keyword *string `query:"keyword"`
|
||||
Status *fields.PostStatus `query:"status"`
|
||||
}
|
||||
|
||||
@@ -44,8 +44,7 @@ type posts struct {
|
||||
// @Bind query query
|
||||
// @Bind user local
|
||||
func (ctl *posts) List(ctx fiber.Ctx, query *dto.PostListQuery, user *models.User) (*requests.Pager, error) {
|
||||
query.Status = fields.PostStatusPublished
|
||||
|
||||
query.Status = lo.ToPtr(fields.PostStatusPublished)
|
||||
pager, err := services.Posts.List(ctx, query)
|
||||
if err != nil {
|
||||
log.WithError(err).Errorf("post list err: %v", err)
|
||||
|
||||
@@ -42,6 +42,11 @@ func (m *posts) List(ctx context.Context, filter *dto.PostListQuery) (*requests.
|
||||
query = query.Where(tbl.Title.Like(keyword))
|
||||
}
|
||||
|
||||
// filter status
|
||||
if filter.Status != nil {
|
||||
query = query.Where(tbl.Status.Eq(*filter.Status))
|
||||
}
|
||||
|
||||
items, cnt, err := query.FindByPage(int(filter.Offset()), int(filter.Limit))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "list post failed")
|
||||
|
||||
Reference in New Issue
Block a user