From ed3d8b0e6cceda81e06cb32e38627c996a873873 Mon Sep 17 00:00:00 2001 From: Rogee Date: Sun, 15 Dec 2024 00:07:15 +0800 Subject: [PATCH] fix: issues --- backend/modules/medias/controller.go | 2 +- backend/modules/medias/service.go | 8 ++++---- backend/pkg/service/http/http.go | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/backend/modules/medias/controller.go b/backend/modules/medias/controller.go index 70f693c..ce6d0d8 100644 --- a/backend/modules/medias/controller.go +++ b/backend/modules/medias/controller.go @@ -120,7 +120,7 @@ func (c *Controller) MediaSegment(ctx fiber.Ctx) error { return err } - filepath := c.svc.GetSegmentPath(ctx.Context(), mediaType, model.Hash, segments[0]) + filepath := c.svc.GetSegmentPath(ctx.Context(), mediaType, model.TenantID, model.Hash, segments[0]) return ctx.SendFile(filepath) } diff --git a/backend/modules/medias/service.go b/backend/modules/medias/service.go index d795874..e02268e 100644 --- a/backend/modules/medias/service.go +++ b/backend/modules/medias/service.go @@ -83,7 +83,7 @@ func (svc *Service) GetMediaByID(ctx context.Context, tenantId, userId, id int64 func (svc *Service) ModelToListItem(ctx context.Context, m *model.Medias) *ListItem { item := &ListItem{ ID: m.ID, - Poster: fmt.Sprintf("/static/%s/poster.jpg", m.Hash), + Poster: fmt.Sprintf("/posters/%d/%s.jpg", m.TenantID, m.Hash), Hash: m.Hash, Title: m.Title, Description: m.Description, @@ -253,7 +253,7 @@ func (svc *Service) Upsert(ctx context.Context, tenantId int64, item media_store // 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") + indexPath := filepath.Join(svc.storageConfig.Path, fmt.Sprintf("%d", tenantId), hash, types.String(), "index.m3u8") log.Infof("m3u8 path: %s", indexPath) f, err := os.Open(indexPath) @@ -313,8 +313,8 @@ func (svc *Service) GetM3U8(ctx context.Context, tenantId int64, types pg.MediaT } // 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)) +func (svc *Service) GetSegmentPath(ctx context.Context, t pg.MediaType, tenantId int64, hash string, segment int64) string { + return filepath.Join(svc.storageConfig.Path, fmt.Sprintf("%d", tenantId), hash, t.String(), fmt.Sprintf("%d.ts", segment)) } func (svc *Service) Checkout(ctx context.Context, tenantId, userId, mediaId int64) error { diff --git a/backend/pkg/service/http/http.go b/backend/pkg/service/http/http.go index 6cea40a..acbe7ef 100644 --- a/backend/pkg/service/http/http.go +++ b/backend/pkg/service/http/http.go @@ -18,6 +18,7 @@ import ( "git.ipao.vip/rogeecn/atom" "git.ipao.vip/rogeecn/atom/container" "git.ipao.vip/rogeecn/atom/contracts" + "github.com/gofiber/fiber/v3" "github.com/gofiber/fiber/v3/middleware/favicon" "github.com/gofiber/fiber/v3/middleware/static" log "github.com/sirupsen/logrus" @@ -77,14 +78,22 @@ func Serve(cmd *cobra.Command, args []string) error { engine.Use(mid.WeChatVerify) engine.Use([]string{"/t/:tenant", "/t/:tenant/*"}, mid.WeChatAuth, http.Wechat.Render) + engine.Get("/posters/:tenant/:hash.jpg", func(c fiber.Ctx) error { + tenant := c.Params("tenant") + hash := c.Params("hash") + + return c.SendFile(filepath.Join( + http.Storage.Path, + tenant, + "posters", + hash+".jpg", + )) + }) http.Service.Engine.Use(favicon.New(favicon.Config{ Data: []byte{}, })) - http.Service.Engine.Use("/static", static.New(http.Storage.Path, static.Config{ - Browse: http.App.IsDevMode(), - })) http.Service.Engine.Use("/assets", static.New(filepath.Join(http.Storage.Asset, "assets"), static.Config{ Browse: http.App.IsDevMode(), }))