Compare commits
2 Commits
ef0bb03ea0
...
4704cf6949
| Author | SHA1 | Date | |
|---|---|---|---|
| 4704cf6949 | |||
| ed48ec46a8 |
@@ -23,6 +23,7 @@ import (
|
|||||||
"go.ipao.vip/atom/container"
|
"go.ipao.vip/atom/container"
|
||||||
"go.ipao.vip/atom/contracts"
|
"go.ipao.vip/atom/contracts"
|
||||||
|
|
||||||
|
"github.com/go-pay/errgroup"
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
"github.com/gofiber/fiber/v3/middleware/favicon"
|
"github.com/gofiber/fiber/v3/middleware/favicon"
|
||||||
"github.com/rogeecn/fabfile"
|
"github.com/rogeecn/fabfile"
|
||||||
@@ -93,8 +94,24 @@ func Serve(cmd *cobra.Command, args []string) error {
|
|||||||
svc.Http.Engine.Get("/admin*", checkStaticFile(svc.App.DistAdmin))
|
svc.Http.Engine.Get("/admin*", checkStaticFile(svc.App.DistAdmin))
|
||||||
svc.Http.Engine.Get("/*", checkStaticFile(svc.App.DistWeChat))
|
svc.Http.Engine.Get("/*", checkStaticFile(svc.App.DistWeChat))
|
||||||
|
|
||||||
|
var eg errgroup.Group
|
||||||
|
|
||||||
|
eg.Go(func(ctx context.Context) error {
|
||||||
|
// river job
|
||||||
|
if err := svc.Job.Start(ctx); err != nil {
|
||||||
|
log.WithError(err).Error("job start failed")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer svc.Job.StopAndCancel(ctx)
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
eg.Go(func(ctx context.Context) error {
|
||||||
return svc.Http.Serve(ctx)
|
return svc.Http.Serve(ctx)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return eg.Wait()
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkStaticFile(rootPath string) func(ctx fiber.Ctx) error {
|
func checkStaticFile(rootPath string) func(ctx fiber.Ctx) error {
|
||||||
|
|||||||
@@ -186,8 +186,12 @@ func (ctl *posts) Play(ctx fiber.Ctx, post *models.Post, user *models.User) (*Pl
|
|||||||
// return &PlayUrl{
|
// return &PlayUrl{
|
||||||
// Url: "https://github.com/mediaelement/mediaelement-files/raw/refs/heads/master/big_buck_bunny.mp4",
|
// Url: "https://github.com/mediaelement/mediaelement-files/raw/refs/heads/master/big_buck_bunny.mp4",
|
||||||
// }, nil
|
// }, nil
|
||||||
|
if post.Status != fields.PostStatusPublished {
|
||||||
|
return nil, fiber.ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
preview := true
|
preview := true
|
||||||
|
if user != nil {
|
||||||
bought, err := services.Users.HasBought(ctx, user.ID, post.ID)
|
bought, err := services.Users.HasBought(ctx, user.ID, post.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
preview = false
|
preview = false
|
||||||
@@ -196,6 +200,7 @@ func (ctl *posts) Play(ctx fiber.Ctx, post *models.Post, user *models.User) (*Pl
|
|||||||
if bought {
|
if bought {
|
||||||
preview = false
|
preview = false
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
log.Infof("Fetching play URL for post ID: %d", post.ID)
|
log.Infof("Fetching play URL for post ID: %d", post.ID)
|
||||||
go services.Posts.IncrViewCount(ctx, post.ID)
|
go services.Posts.IncrViewCount(ctx, post.ID)
|
||||||
|
|||||||
@@ -22,7 +22,9 @@ func (f *Middlewares) AuthFrontend(ctx fiber.Ctx) error {
|
|||||||
if strings.HasPrefix(ctx.Path(), "/v1/posts/") && strings.HasSuffix(ctx.Path(), "show") {
|
if strings.HasPrefix(ctx.Path(), "/v1/posts/") && strings.HasSuffix(ctx.Path(), "show") {
|
||||||
return ctx.Next()
|
return ctx.Next()
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(ctx.Path(), "/v1/posts/") && strings.HasSuffix(ctx.Path(), "play") {
|
|
||||||
|
token := ctx.Get("Authorization")
|
||||||
|
if token == "" && strings.HasPrefix(ctx.Path(), "/v1/posts/") && strings.HasSuffix(ctx.Path(), "play") {
|
||||||
return ctx.Next()
|
return ctx.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +49,6 @@ func (f *Middlewares) AuthFrontend(ctx fiber.Ctx) error {
|
|||||||
fullUrl = u.String()
|
fullUrl = u.String()
|
||||||
|
|
||||||
// 仅使用 Header 的 Bearer Token(前端 localStorage 存储,随请求透传)。
|
// 仅使用 Header 的 Bearer Token(前端 localStorage 存储,随请求透传)。
|
||||||
token := ctx.Get("Authorization")
|
|
||||||
if token == "" {
|
if token == "" {
|
||||||
log.Infof("auth redirect_uri: %s", fullUrl)
|
log.Infof("auth redirect_uri: %s", fullUrl)
|
||||||
if ctx.XHR() {
|
if ctx.XHR() {
|
||||||
@@ -73,6 +74,7 @@ func (f *Middlewares) AuthFrontend(ctx fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ctx.Locals("user", user)
|
ctx.Locals("user", user)
|
||||||
|
log.Infof("jwt login user id: %d", user.ID)
|
||||||
|
|
||||||
return ctx.Next()
|
return ctx.Next()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user