feat: 添加媒体播放功能,支持基于短时效token的播放入口及相关API接口
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
package tenant
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"quyun/v2/app/errorx"
|
||||
"quyun/v2/app/http/tenant/dto"
|
||||
"quyun/v2/app/requests"
|
||||
@@ -104,13 +108,32 @@ func (*content) previewAssets(ctx fiber.Ctx, tenant *models.Tenant, user *models
|
||||
return nil, err
|
||||
}
|
||||
|
||||
playables := make([]*dto.ContentPlayableAsset, 0, len(assets))
|
||||
for _, asset := range assets {
|
||||
token, expiresAt, err := services.MediaDelivery.CreatePlayToken(tenant.ID, contentID, asset.ID, consts.ContentAssetRolePreview, user.ID, 0, time.Now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var meta json.RawMessage
|
||||
if len(asset.Meta) > 0 {
|
||||
meta = json.RawMessage(asset.Meta)
|
||||
}
|
||||
playables = append(playables, &dto.ContentPlayableAsset{
|
||||
AssetID: asset.ID,
|
||||
Type: asset.Type,
|
||||
PlayURL: "/t/" + tenant.Code + "/v1/media/play?token=" + url.QueryEscape(token),
|
||||
ExpiresAt: expiresAt,
|
||||
Meta: meta,
|
||||
})
|
||||
}
|
||||
|
||||
previewSeconds := int32(detail.Content.PreviewSeconds)
|
||||
if previewSeconds <= 0 {
|
||||
previewSeconds = consts.DefaultContentPreviewSeconds
|
||||
}
|
||||
return &dto.ContentAssetsResponse{
|
||||
Content: detail.Content,
|
||||
Assets: assets,
|
||||
Assets: playables,
|
||||
PreviewSeconds: previewSeconds,
|
||||
}, nil
|
||||
}
|
||||
@@ -150,8 +173,27 @@ func (*content) mainAssets(ctx fiber.Ctx, tenant *models.Tenant, user *models.Us
|
||||
return nil, err
|
||||
}
|
||||
|
||||
playables := make([]*dto.ContentPlayableAsset, 0, len(assets))
|
||||
for _, asset := range assets {
|
||||
token, expiresAt, err := services.MediaDelivery.CreatePlayToken(tenant.ID, contentID, asset.ID, consts.ContentAssetRoleMain, user.ID, 0, time.Now())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var meta json.RawMessage
|
||||
if len(asset.Meta) > 0 {
|
||||
meta = json.RawMessage(asset.Meta)
|
||||
}
|
||||
playables = append(playables, &dto.ContentPlayableAsset{
|
||||
AssetID: asset.ID,
|
||||
Type: asset.Type,
|
||||
PlayURL: "/t/" + tenant.Code + "/v1/media/play?token=" + url.QueryEscape(token),
|
||||
ExpiresAt: expiresAt,
|
||||
Meta: meta,
|
||||
})
|
||||
}
|
||||
|
||||
return &dto.ContentAssetsResponse{
|
||||
Content: detail.Content,
|
||||
Assets: assets,
|
||||
Assets: playables,
|
||||
}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user