fix: issues
This commit is contained in:
Binary file not shown.
@@ -8,7 +8,7 @@ require (
|
|||||||
github.com/gofiber/fiber/v3 v3.0.0-beta.3
|
github.com/gofiber/fiber/v3 v3.0.0-beta.3
|
||||||
github.com/gofrs/uuid v4.4.0+incompatible
|
github.com/gofrs/uuid v4.4.0+incompatible
|
||||||
github.com/golang-jwt/jwt/v4 v4.5.1
|
github.com/golang-jwt/jwt/v4 v4.5.1
|
||||||
github.com/google/uuid v1.6.0
|
github.com/grafov/m3u8 v0.12.1
|
||||||
github.com/imroc/req/v3 v3.48.0
|
github.com/imroc/req/v3 v3.48.0
|
||||||
github.com/jinzhu/copier v0.4.0
|
github.com/jinzhu/copier v0.4.0
|
||||||
github.com/juju/go4 v0.0.0-20160222163258-40d72ab9641a
|
github.com/juju/go4 v0.0.0-20160222163258-40d72ab9641a
|
||||||
@@ -38,6 +38,7 @@ require (
|
|||||||
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
|
||||||
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
|
github.com/gofiber/utils/v2 v2.0.0-beta.4 // indirect
|
||||||
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 // indirect
|
github.com/google/pprof v0.0.0-20240910150728-a0b0bb1d4134 // indirect
|
||||||
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 // indirect
|
||||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||||
|
|||||||
@@ -159,6 +159,8 @@ github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5m
|
|||||||
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
|
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8/go.mod h1:dvDLG8qkwmyD9a/MJJN3XJcT3xFxOKAvTZGvuZmac9g=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1 h1:EGx4pi6eqNxGaHF6qqu48+N2wcFQ5qg5FXgOdqsJ5d8=
|
||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
|
github.com/grafov/m3u8 v0.12.1 h1:DuP1uA1kvRRmGNAZ0m+ObLv1dvrfNO0TPx0c/enNk0s=
|
||||||
|
github.com/grafov/m3u8 v0.12.1/go.mod h1:nqzOkfBiZJENr52zTVd/Dcl03yzphIMbJqkXGu+u080=
|
||||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
|
||||||
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||||
|
|||||||
@@ -4,11 +4,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/common/service/http"
|
"backend/pkg/service/http"
|
||||||
"backend/common/service/migrate"
|
"backend/pkg/service/migrate"
|
||||||
"backend/common/service/model"
|
"backend/pkg/service/model"
|
||||||
"backend/common/service/tasks"
|
"backend/pkg/service/tasks"
|
||||||
"backend/common/service/tenants"
|
"backend/pkg/service/tenants"
|
||||||
|
|
||||||
"git.ipao.vip/rogeecn/atom"
|
"git.ipao.vip/rogeecn/atom"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"backend/common/service/model"
|
|
||||||
"backend/pkg/pg"
|
"backend/pkg/pg"
|
||||||
|
"backend/pkg/service/model"
|
||||||
"backend/providers/wechat"
|
"backend/providers/wechat"
|
||||||
|
|
||||||
"git.ipao.vip/rogeecn/atom"
|
"git.ipao.vip/rogeecn/atom"
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"backend/common/media_store"
|
|
||||||
"backend/modules/medias"
|
"backend/modules/medias"
|
||||||
|
"backend/pkg/media_store"
|
||||||
"backend/pkg/path"
|
"backend/pkg/path"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|||||||
@@ -4,9 +4,9 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"backend/common/media_store"
|
|
||||||
"backend/common/service/testx"
|
|
||||||
"backend/modules/medias"
|
"backend/modules/medias"
|
||||||
|
"backend/pkg/media_store"
|
||||||
|
"backend/pkg/service/testx"
|
||||||
"backend/providers/postgres"
|
"backend/providers/postgres"
|
||||||
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ package store
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"backend/common/media_store"
|
|
||||||
"backend/modules/medias"
|
"backend/modules/medias"
|
||||||
|
"backend/pkg/media_store"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|||||||
@@ -1,17 +1,20 @@
|
|||||||
package medias
|
package medias
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/common/consts"
|
"backend/pkg/consts"
|
||||||
"backend/common/errorx"
|
"backend/pkg/errorx"
|
||||||
|
"backend/pkg/pg"
|
||||||
"backend/providers/jwt"
|
"backend/providers/jwt"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
hashids "github.com/speps/go-hashids/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @provider
|
// @provider
|
||||||
type Controller struct {
|
type Controller struct {
|
||||||
svc *Service
|
hashIds *hashids.HashID
|
||||||
|
svc *Service
|
||||||
}
|
}
|
||||||
|
|
||||||
// List
|
// List
|
||||||
@@ -54,10 +57,60 @@ func (c *Controller) Show(ctx fiber.Ctx) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
func (c *Controller) Video(ctx fiber.Ctx) error {
|
func (c *Controller) MediaIndex(ctx fiber.Ctx) error {
|
||||||
// mediaId := ToInt64(ctx.Params("media"))
|
mediaType, err := pg.ParseMediaType(ctx.Params("type"))
|
||||||
// tenantId := ToInt64(ctx.Locals("tenantId"))
|
if err != nil {
|
||||||
// userId := ToInt64(ctx.Locals("userId"))
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.RequestParseError)
|
||||||
|
}
|
||||||
|
|
||||||
return ctx.JSON(nil)
|
hash := ctx.Params("hash")
|
||||||
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
|
log.Debug(claim)
|
||||||
|
|
||||||
|
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("action", "medias.MediaIndex").WithError(err).Error("GetMediaByHash")
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
|
||||||
|
}
|
||||||
|
|
||||||
|
bought, err := c.svc.HasUserBought(ctx.Context(), claim.TenantID, claim.UserID, model.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("action", "medias.MediaIndex").WithError(err).Error("HasUserBought")
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
|
||||||
|
}
|
||||||
|
|
||||||
|
playlist, err := c.svc.GetM3U8(ctx.Context(), claim.TenantID, mediaType, model.Hash, bought)
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("action", "medias.MediaIndex").WithError(err).Error("GetMediaPlaylist")
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
|
||||||
|
}
|
||||||
|
|
||||||
|
return ctx.SendString(playlist.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Controller) MediaSegment(ctx fiber.Ctx) error {
|
||||||
|
mediaType, err := pg.ParseMediaType(ctx.Params("type"))
|
||||||
|
if err != nil {
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.RequestParseError)
|
||||||
|
}
|
||||||
|
|
||||||
|
segment := ctx.Params("segment")
|
||||||
|
segments, err := c.hashIds.DecodeInt64WithError(segment)
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("action", "medias.MediaSegment").WithError(err).Error("DecodeInt64WithError")
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.RequestParseError)
|
||||||
|
}
|
||||||
|
|
||||||
|
hash := ctx.Params("hash")
|
||||||
|
claim := fiber.Locals[*jwt.Claims](ctx, consts.CtxKeyClaim)
|
||||||
|
log.Debug(claim)
|
||||||
|
|
||||||
|
model, err := c.svc.GetMediaByHash(ctx.Context(), claim.TenantID, hash)
|
||||||
|
if err != nil {
|
||||||
|
log.WithField("action", "medias.MediaSegment").WithError(err).Error("GetMediaByHash")
|
||||||
|
return ctx.Status(fiber.StatusInternalServerError).JSON(errorx.InternalError)
|
||||||
|
}
|
||||||
|
|
||||||
|
filepath := c.svc.GetSegmentPath(ctx.Context(), mediaType, model.Hash, segments[0])
|
||||||
|
return ctx.SendFile(filepath)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,14 +8,17 @@ import (
|
|||||||
"git.ipao.vip/rogeecn/atom/container"
|
"git.ipao.vip/rogeecn/atom/container"
|
||||||
"git.ipao.vip/rogeecn/atom/contracts"
|
"git.ipao.vip/rogeecn/atom/contracts"
|
||||||
"git.ipao.vip/rogeecn/atom/utils/opt"
|
"git.ipao.vip/rogeecn/atom/utils/opt"
|
||||||
|
hashids "github.com/speps/go-hashids/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func Provide(opts ...opt.Option) error {
|
func Provide(opts ...opt.Option) error {
|
||||||
if err := container.Container.Provide(func(
|
if err := container.Container.Provide(func(
|
||||||
|
hashIds *hashids.HashID,
|
||||||
svc *Service,
|
svc *Service,
|
||||||
) (*Controller, error) {
|
) (*Controller, error) {
|
||||||
obj := &Controller{
|
obj := &Controller{
|
||||||
svc: svc,
|
hashIds: hashIds,
|
||||||
|
svc: svc,
|
||||||
}
|
}
|
||||||
return obj, nil
|
return obj, nil
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
@@ -38,10 +41,12 @@ func Provide(opts ...opt.Option) error {
|
|||||||
|
|
||||||
if err := container.Container.Provide(func(
|
if err := container.Container.Provide(func(
|
||||||
db *sql.DB,
|
db *sql.DB,
|
||||||
|
hashIds *hashids.HashID,
|
||||||
storageConfig *storage.Config,
|
storageConfig *storage.Config,
|
||||||
) (*Service, error) {
|
) (*Service, error) {
|
||||||
obj := &Service{
|
obj := &Service{
|
||||||
db: db,
|
db: db,
|
||||||
|
hashIds: hashIds,
|
||||||
storageConfig: storageConfig,
|
storageConfig: storageConfig,
|
||||||
}
|
}
|
||||||
if err := obj.Prepare(); err != nil {
|
if err := obj.Prepare(); err != nil {
|
||||||
|
|||||||
@@ -27,4 +27,6 @@ func (r *Router) Register(router fiber.Router) {
|
|||||||
group := router.Group(r.Name())
|
group := router.Group(r.Name())
|
||||||
group.Post("", r.controller.List)
|
group.Post("", r.controller.List)
|
||||||
group.Get(":hash", r.controller.Show)
|
group.Get(":hash", r.controller.Show)
|
||||||
|
group.Get(":hash/:type<regex([video|audio])>", r.controller.MediaIndex)
|
||||||
|
group.Get(":hash/:type<regex([video|audio])>/:segment.ts", r.controller.MediaSegment)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,27 +1,34 @@
|
|||||||
package medias
|
package medias
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"backend/common/media_store"
|
|
||||||
"backend/database/models/qvyun/public/model"
|
"backend/database/models/qvyun/public/model"
|
||||||
"backend/database/models/qvyun/public/table"
|
"backend/database/models/qvyun/public/table"
|
||||||
|
"backend/pkg/media_store"
|
||||||
"backend/pkg/path"
|
"backend/pkg/path"
|
||||||
"backend/pkg/pg"
|
"backend/pkg/pg"
|
||||||
"backend/providers/storage"
|
"backend/providers/storage"
|
||||||
|
|
||||||
. "github.com/go-jet/jet/v2/postgres"
|
. "github.com/go-jet/jet/v2/postgres"
|
||||||
|
"github.com/grafov/m3u8"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/samber/lo"
|
"github.com/samber/lo"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
hashids "github.com/speps/go-hashids/v2"
|
||||||
|
"github.com/spf13/cast"
|
||||||
)
|
)
|
||||||
|
|
||||||
// @provider:except
|
// @provider:except
|
||||||
type Service struct {
|
type Service struct {
|
||||||
db *sql.DB
|
db *sql.DB
|
||||||
|
hashIds *hashids.HashID
|
||||||
storageConfig *storage.Config
|
storageConfig *storage.Config
|
||||||
log *logrus.Entry `inject:"false"`
|
log *logrus.Entry `inject:"false"`
|
||||||
}
|
}
|
||||||
@@ -244,3 +251,66 @@ func (svc *Service) Upsert(ctx context.Context, tenantId int64, item media_store
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get video m3u8
|
||||||
|
func (svc *Service) GetM3U8(ctx context.Context, tenantId int64, types pg.MediaType, hash string, bought bool) (m3u8.Playlist, error) {
|
||||||
|
log := svc.log.WithField("method", "GetM3U8")
|
||||||
|
indexPath := filepath.Join(svc.storageConfig.Path, hash, types.String(), "index.m3u8")
|
||||||
|
log.Infof("m3u8 path: %s", indexPath)
|
||||||
|
|
||||||
|
f, err := os.Open(indexPath)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "open index file")
|
||||||
|
}
|
||||||
|
|
||||||
|
p, listType, err := m3u8.DecodeFrom(bufio.NewReader(f), true)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "decode index file")
|
||||||
|
}
|
||||||
|
|
||||||
|
if listType != m3u8.MEDIA {
|
||||||
|
return nil, errors.New("Invalid media file")
|
||||||
|
}
|
||||||
|
|
||||||
|
media, ok := p.(*m3u8.MediaPlaylist)
|
||||||
|
if !ok {
|
||||||
|
return nil, errors.New("Invalid media playlist")
|
||||||
|
}
|
||||||
|
media.Segments = lo.Filter(media.Segments, func(seg *m3u8.MediaSegment, _ int) bool {
|
||||||
|
return seg != nil
|
||||||
|
})
|
||||||
|
|
||||||
|
if !bought {
|
||||||
|
duration := 0
|
||||||
|
for i, seg := range media.Segments {
|
||||||
|
duration += int(seg.Duration)
|
||||||
|
if duration >= 55 {
|
||||||
|
media.Segments = media.Segments[:i]
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, seg := range media.Segments {
|
||||||
|
// remove seg.URI ext, only keep the name
|
||||||
|
name, ext := path.SplitNameExt(seg.URI)
|
||||||
|
nameId, err := cast.ToInt64E(name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "cast index to int64")
|
||||||
|
}
|
||||||
|
|
||||||
|
// get video info
|
||||||
|
hashID, err := svc.hashIds.EncodeInt64([]int64{nameId})
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "encode hash id")
|
||||||
|
}
|
||||||
|
seg.URI = fmt.Sprintf("%s/%s.%s", types, hashID, ext)
|
||||||
|
}
|
||||||
|
|
||||||
|
return media, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSegmentPath
|
||||||
|
func (svc *Service) GetSegmentPath(ctx context.Context, t pg.MediaType, hash string, segment int64) string {
|
||||||
|
return filepath.Join(svc.storageConfig.Path, hash, t.String(), fmt.Sprintf("%d.ts", segment))
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,48 +4,65 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"backend/database/models/qvyun/public/model"
|
"backend/pkg/path"
|
||||||
"backend/database/models/qvyun/public/table"
|
"backend/pkg/pg"
|
||||||
"backend/fixtures"
|
"backend/pkg/service/testx"
|
||||||
dbUtil "backend/pkg/db"
|
"backend/providers/hashids"
|
||||||
|
"backend/providers/postgres"
|
||||||
|
"backend/providers/storage"
|
||||||
|
|
||||||
"github.com/samber/lo"
|
|
||||||
. "github.com/smartystreets/goconvey/convey"
|
. "github.com/smartystreets/goconvey/convey"
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"go.uber.org/dig"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestService_GetUserBoughtMedias(t *testing.T) {
|
type ServiceInjectParams struct {
|
||||||
Convey("TestService_GetUserBoughtMedias", t, func() {
|
dig.In
|
||||||
db, err := fixtures.GetDB()
|
Svc *Service
|
||||||
So(err, ShouldBeNil)
|
}
|
||||||
defer db.Close()
|
|
||||||
|
|
||||||
So(dbUtil.TruncateAllTables(context.TODO(), db, "user_medias"), ShouldBeNil)
|
type ServiceTestSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
ServiceInjectParams
|
||||||
|
}
|
||||||
|
|
||||||
Convey("insert some data", func() {
|
func Test_DiscoverMedias(t *testing.T) {
|
||||||
items := []model.UserMedias{
|
providers := testx.Default(
|
||||||
{UserID: 1, TenantID: 1, MediaID: 1, Price: 10},
|
postgres.DefaultProvider(),
|
||||||
{UserID: 1, TenantID: 1, MediaID: 2, Price: 10},
|
storage.DefaultProvider(),
|
||||||
{UserID: 1, TenantID: 1, MediaID: 3, Price: 10},
|
hashids.DefaultProvider(),
|
||||||
}
|
).With(
|
||||||
|
Provide,
|
||||||
|
)
|
||||||
|
|
||||||
tbl := table.UserMedias
|
testx.Serve(providers, t, func(params ServiceInjectParams) {
|
||||||
stmt := tbl.INSERT(tbl.UserID, tbl.TenantID, tbl.MediaID, tbl.Price).MODELS(items)
|
suite.Run(t, &ServiceTestSuite{ServiceInjectParams: params})
|
||||||
t.Log(stmt.DebugSql())
|
})
|
||||||
|
}
|
||||||
|
|
||||||
_, err := stmt.Exec(db)
|
func (t *ServiceTestSuite) Test_getM3U8() {
|
||||||
|
FocusConvey("Test_ffmpegVideoToM3U8", t.T(), func() {
|
||||||
|
Convey("Bought", func() {
|
||||||
|
hash := "f464a6641a60e2722e4042db8fad2813"
|
||||||
|
media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, true)
|
||||||
So(err, ShouldBeNil)
|
So(err, ShouldBeNil)
|
||||||
|
t.T().Logf("%+v", media)
|
||||||
|
})
|
||||||
|
|
||||||
Convey("get user bought medias", func() {
|
FocusConvey("Not Bought", func() {
|
||||||
svc := &Service{db: db}
|
hash := "f464a6641a60e2722e4042db8fad2813"
|
||||||
So(svc.Prepare(), ShouldBeNil)
|
media, err := t.Svc.GetM3U8(context.Background(), 1, pg.MediaTypeVideo, hash, false)
|
||||||
|
So(err, ShouldBeNil)
|
||||||
ids, err := svc.GetUserBoughtMedias(context.TODO(), 1, 1)
|
t.T().Logf("%+v", media)
|
||||||
So(err, ShouldBeNil)
|
|
||||||
|
|
||||||
for _, id := range ids {
|
|
||||||
So(lo.Contains([]int64{1, 2, 3}, id), ShouldBeTrue)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *ServiceTestSuite) Test_getMediaByHash() {
|
||||||
|
Convey("Test_getMediaByHash", t.T(), func() {
|
||||||
|
name, ext := path.SplitNameExt("0.ts")
|
||||||
|
|
||||||
|
So(name, ShouldEqual, "0")
|
||||||
|
So(ext, ShouldEqual, "ts")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package middlewares
|
package middlewares
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"backend/common/consts"
|
"backend/pkg/consts"
|
||||||
|
|
||||||
"github.com/gofiber/fiber/v3"
|
"github.com/gofiber/fiber/v3"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
|
|||||||
@@ -5,9 +5,9 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"backend/common/consts"
|
|
||||||
"backend/database/models/qvyun/public/model"
|
"backend/database/models/qvyun/public/model"
|
||||||
"backend/database/models/qvyun/public/table"
|
"backend/database/models/qvyun/public/table"
|
||||||
|
"backend/pkg/consts"
|
||||||
"backend/pkg/db"
|
"backend/pkg/db"
|
||||||
"backend/pkg/pg"
|
"backend/pkg/pg"
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
"database/sql"
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"backend/common/consts"
|
"backend/pkg/consts"
|
||||||
|
|
||||||
"github.com/go-jet/jet/v2/qrm"
|
"github.com/go-jet/jet/v2/qrm"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package path
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
@@ -35,3 +37,10 @@ func DirExists(path string) bool {
|
|||||||
}
|
}
|
||||||
return st.IsDir()
|
return st.IsDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SplitNameExt(name string) (string, string) {
|
||||||
|
ext := filepath.Ext(name)
|
||||||
|
name = name[:len(name)-len(ext)]
|
||||||
|
|
||||||
|
return name, strings.TrimLeft(ext, ".")
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import (
|
|||||||
"backend/modules/middlewares"
|
"backend/modules/middlewares"
|
||||||
"backend/modules/users"
|
"backend/modules/users"
|
||||||
"backend/providers/app"
|
"backend/providers/app"
|
||||||
|
"backend/providers/hashids"
|
||||||
"backend/providers/http"
|
"backend/providers/http"
|
||||||
"backend/providers/jwt"
|
"backend/providers/jwt"
|
||||||
"backend/providers/postgres"
|
"backend/providers/postgres"
|
||||||
@@ -25,6 +26,7 @@ func defaultProviders(providers ...container.ProviderContainer) container.Provid
|
|||||||
http.DefaultProvider(),
|
http.DefaultProvider(),
|
||||||
postgres.DefaultProvider(),
|
postgres.DefaultProvider(),
|
||||||
jwt.DefaultProvider(),
|
jwt.DefaultProvider(),
|
||||||
|
hashids.DefaultProvider(),
|
||||||
}, providers...)
|
}, providers...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -4,8 +4,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"backend/providers/hashids"
|
|
||||||
|
|
||||||
"git.ipao.vip/rogeecn/atom"
|
"git.ipao.vip/rogeecn/atom"
|
||||||
"git.ipao.vip/rogeecn/atom/container"
|
"git.ipao.vip/rogeecn/atom/container"
|
||||||
"github.com/rogeecn/fabfile"
|
"github.com/rogeecn/fabfile"
|
||||||
@@ -13,9 +11,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func Default(providers ...container.ProviderContainer) container.Providers {
|
func Default(providers ...container.ProviderContainer) container.Providers {
|
||||||
return append(container.Providers{
|
return append(container.Providers{}, providers...)
|
||||||
hashids.DefaultProvider(),
|
|
||||||
}, providers...)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Serve(providers container.Providers, t *testing.T, invoke any) {
|
func Serve(providers container.Providers, t *testing.T, invoke any) {
|
||||||
@@ -12,4 +12,12 @@ Authorization: {{ Token }}
|
|||||||
### Get Media
|
### Get Media
|
||||||
GET {{host}}/v1/medias/f464a6641a60e2722e4042db8fad2813
|
GET {{host}}/v1/medias/f464a6641a60e2722e4042db8fad2813
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
|
Authorization: {{ Token }}
|
||||||
|
|
||||||
|
### Get media index
|
||||||
|
GET {{host}}/v1/medias/f464a6641a60e2722e4042db8fad2813/video
|
||||||
|
Authorization: {{ Token }}
|
||||||
|
|
||||||
|
### Get media segment
|
||||||
|
GET {{host}}/v1/medias/f464a6641a60e2722e4042db8fad2813/video/Jk0eyPxqlX.ts
|
||||||
Authorization: {{ Token }}
|
Authorization: {{ Token }}
|
||||||
Reference in New Issue
Block a user