fix: purchase ui

This commit is contained in:
Rogee
2025-05-14 20:39:36 +08:00
parent 308da6113e
commit 6876d8bcd7
3 changed files with 89 additions and 19 deletions

View File

@@ -173,6 +173,12 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
// Url: "https://github.com/mediaelement/mediaelement-files/raw/refs/heads/master/big_buck_bunny.mp4",
// }, nil
preview := false
bought, err := models.Users.HasBought(ctx.Context(), user.ID, id)
if !bought || err != nil {
preview = true
}
log.Infof("Fetching play URL for post ID: %d", id)
post, err := models.Posts.GetByID(ctx.Context(), id)
if err != nil {
@@ -181,12 +187,6 @@ func (ctl *posts) Play(ctx fiber.Ctx, id int64, user *model.Users) (*PlayUrl, er
}
go models.Posts.IncrViewCount(ctx.Context(), post.ID)
preview := false
bought, err := models.Users.HasBought(ctx.Context(), user.ID, post.ID)
if !bought || err != nil {
preview = true
}
for _, asset := range post.Assets.Data {
if asset.Type == "video/mp4" && asset.Metas != nil && asset.Metas.Short == preview {
media, err := models.Medias.GetByID(ctx.Context(), asset.Media)