feat: publish complete
This commit is contained in:
@@ -12,8 +12,9 @@ import (
|
||||
type Store []UUIDMap
|
||||
|
||||
type UUIDMap struct {
|
||||
UUID string
|
||||
Name string
|
||||
UUID string
|
||||
Name string
|
||||
Price uint
|
||||
}
|
||||
|
||||
func NewStore(path string) (Store, error) {
|
||||
@@ -55,8 +56,8 @@ func (s Store) Save(path string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s Store) Add(uuid, name string) {
|
||||
s = append(s, UUIDMap{UUID: uuid, Name: name})
|
||||
func (s Store) Add(uuid, name string, price uint) {
|
||||
s = append(s, UUIDMap{UUID: uuid, Name: name, Price: price})
|
||||
}
|
||||
|
||||
func (s Store) UUIDs() []string {
|
||||
|
||||
@@ -4,7 +4,6 @@ go 1.22.0
|
||||
|
||||
require (
|
||||
git.ipao.vip/rogeecn/atom v1.0.10
|
||||
github.com/etherlabsio/go-m3u8 v1.0.0
|
||||
github.com/go-jet/jet/v2 v2.12.0
|
||||
github.com/gofiber/fiber/v3 v3.0.0-beta.3
|
||||
github.com/gofrs/uuid v4.4.0+incompatible
|
||||
|
||||
@@ -38,7 +38,6 @@ cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3f
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
git.ipao.vip/rogeecn/atom v1.0.10 h1:U/10G17rkULOAhgqGUD6rhcdJ5vJNxGv5gelAZTcJeU=
|
||||
git.ipao.vip/rogeecn/atom v1.0.10/go.mod h1:YY1nlkYnMpZxen5R64mblMWm+LJYyvWiw3P8P2eO7dY=
|
||||
github.com/AlekSi/pointer v1.0.0/go.mod h1:1kjywbfcPFCmncIxtk6fIEub6LKrfMz3gc5QKVOSOA8=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
|
||||
@@ -71,8 +70,6 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
|
||||
github.com/envoyproxy/go-control-plane v0.9.7/go.mod h1:cwu0lG7PUMfa9snN8LXBig5ynNVH9qI8YYLbd1fK2po=
|
||||
github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk=
|
||||
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
|
||||
github.com/etherlabsio/go-m3u8 v1.0.0 h1:d3HJVr8wlbvJO20ksKEyvDYf4bcM7v8YV3W83fHswL0=
|
||||
github.com/etherlabsio/go-m3u8 v1.0.0/go.mod h1:RzDiaXgaYnIEzZUmVUD/xMRFR7bY7U5JaCnp8XYLmXU=
|
||||
github.com/frankban/quicktest v1.2.2/go.mod h1:Qh/WofXFeiAFII1aEBu529AtJo6Zg2VHscnEsbBnJ20=
|
||||
github.com/frankban/quicktest v1.14.4 h1:g2rn0vABPOOXmZUj+vbmUp0lPoXEMuhTpIluN0XL9UY=
|
||||
github.com/frankban/quicktest v1.14.4/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
|
||||
|
||||
@@ -207,7 +207,7 @@ func (svc *Service) GetTenantUUIDs(ctx context.Context, tenantId int64) ([]strin
|
||||
}
|
||||
|
||||
// PublishTenant
|
||||
func (svc *Service) PublishTenantMedia(ctx context.Context, tenantId int64, uuid uuid.UUID, name string) error {
|
||||
func (svc *Service) PublishTenantMedia(ctx context.Context, tenantId int64, uuid uuid.UUID, name string, price uint) error {
|
||||
log := svc.log.WithField("method", "PublishTenant")
|
||||
|
||||
resources := pg.MediaResources{}
|
||||
@@ -225,8 +225,8 @@ func (svc *Service) PublishTenantMedia(ctx context.Context, tenantId int64, uuid
|
||||
|
||||
tbl := table.Medias
|
||||
stmt := tbl.
|
||||
INSERT(tbl.TenantID, tbl.UUID, tbl.Title, tbl.Resources).
|
||||
VALUES(Int(tenantId), UUID(uuid), String(name), Json(resources.MustValue()))
|
||||
INSERT(tbl.TenantID, tbl.UUID, tbl.Title, tbl.Price, tbl.Resources, tbl.Publish).
|
||||
VALUES(Int(tenantId), UUID(uuid), String(name), Int(int64(price)), Json(resources.MustValue()), Bool(true))
|
||||
log.Debug(stmt.DebugSql())
|
||||
|
||||
if _, err := stmt.ExecContext(ctx, svc.db); err != nil {
|
||||
|
||||
@@ -195,13 +195,13 @@ func TestService_PublishTenant(t *testing.T) {
|
||||
}
|
||||
So(svc.Prepare(), ShouldBeNil)
|
||||
|
||||
err := svc.PublishTenantMedia(context.TODO(), 1, items[0].UUID, items[0].Title)
|
||||
err := svc.PublishTenantMedia(context.TODO(), 1, items[0].UUID, items[0].Title, 100)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = svc.PublishTenantMedia(context.TODO(), 1, items[1].UUID, items[1].Title)
|
||||
err = svc.PublishTenantMedia(context.TODO(), 1, items[1].UUID, items[1].Title, 200)
|
||||
So(err, ShouldBeNil)
|
||||
|
||||
err = svc.PublishTenantMedia(context.TODO(), 1, items[2].UUID, items[2].Title)
|
||||
err = svc.PublishTenantMedia(context.TODO(), 1, items[2].UUID, items[2].Title, 300)
|
||||
So(err, ShouldBeNil)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package discover
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"backend/common/media_store"
|
||||
@@ -84,7 +86,12 @@ func (d *DiscoverMedias) RunE(from, to string) error {
|
||||
}
|
||||
}
|
||||
|
||||
store.Add(uuid, dir)
|
||||
price, err := d.getPrice(dirPath)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "get price: %s", dirPath)
|
||||
}
|
||||
|
||||
store.Add(uuid, dir, price)
|
||||
if err := store.Save(to); err != nil {
|
||||
return errors.Wrapf(err, "store save: %s", to)
|
||||
}
|
||||
@@ -241,3 +248,23 @@ func (d *DiscoverMedias) ffmpegVideoToPoster(video string, output string, second
|
||||
d.log.Infof("get snapshot: %s", logs)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (d *DiscoverMedias) getPrice(dir string) (uint, error) {
|
||||
price, err := os.ReadFile(filepath.Join(dir, "price.txt"))
|
||||
if err != nil {
|
||||
return 0, errors.Wrapf(err, "read price: %s", dir)
|
||||
}
|
||||
|
||||
if len(price) == 0 {
|
||||
return 0, fmt.Errorf("%s, price is empty", dir)
|
||||
}
|
||||
|
||||
price = bytes.TrimSpace(price)
|
||||
|
||||
p, err := strconv.Atoi(string(price))
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf(dir, ", price is not a number")
|
||||
}
|
||||
|
||||
return uint(p), nil
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func (d *StoreMedias) RunE(targetPath string) error {
|
||||
return errors.Wrap(err, "uuid from bytes")
|
||||
}
|
||||
|
||||
if err := d.mediasSvc.PublishTenantMedia(context.Background(), 1, u, item.Name); err != nil {
|
||||
if err := d.mediasSvc.PublishTenantMedia(context.Background(), 1, u, item.Name, item.Price); err != nil {
|
||||
return errors.Wrapf(err, "PublishTenant: %+v", item)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user