feat: 实现媒体播放功能,支持本地文件和重定向,添加相关测试用例
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package tenant_media
|
||||
|
||||
import (
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/services"
|
||||
"quyun/v2/database/models"
|
||||
|
||||
@@ -30,9 +31,20 @@ func (*media) play(ctx fiber.Ctx, tenant *models.Tenant, token string) error {
|
||||
"tenant_id": tenant.ID,
|
||||
}).Info("tenant_media.play")
|
||||
|
||||
location, err := services.MediaDelivery.ResolvePlayRedirect(ctx.Context(), tenant.ID, token)
|
||||
res, err := services.MediaDelivery.ResolvePlay(ctx.Context(), tenant.ID, token)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return ctx.Redirect().To(location)
|
||||
|
||||
switch res.Kind {
|
||||
case services.MediaPlayResolutionKindLocalFile:
|
||||
if res.ContentType != "" {
|
||||
ctx.Set("Content-Type", res.ContentType)
|
||||
}
|
||||
return ctx.SendFile(res.LocalFilePath)
|
||||
case services.MediaPlayResolutionKindRedirect:
|
||||
return ctx.Redirect().To(res.RedirectURL)
|
||||
default:
|
||||
return errorx.ErrServiceUnavailable.WithMsg("unsupported play resolution")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user