feat: Introduce MediaAssetVariant for better asset management
- Added MediaAssetVariant enum with values 'main' and 'preview'. - Updated media asset service logic to utilize MediaAssetVariant for variant handling. - Refactored database models and queries to include variant and source_asset_id fields. - Enhanced validation for asset variants in upload and processing functions. - Updated Swagger documentation to reflect new variant structure and descriptions. - Implemented necessary database migrations to support the new variant constraints.
This commit is contained in:
@@ -12,7 +12,6 @@ import (
|
||||
|
||||
jwtlib "github.com/golang-jwt/jwt/v4"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"go.ipao.vip/gen/types"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
@@ -126,10 +125,13 @@ func (s *mediaDelivery) ResolvePlayRedirect(ctx context.Context, tenantID int64,
|
||||
"exp": claims.ExpiresAt,
|
||||
}).Info("services.media_delivery.resolve_play_redirect")
|
||||
|
||||
var asset models.MediaAsset
|
||||
if err := _db.WithContext(ctx).
|
||||
Where("tenant_id = ? AND id = ? AND deleted_at IS NULL", tenantID, claims.AssetID).
|
||||
First(&asset).Error; err != nil {
|
||||
tblAsset, queryAsset := models.MediaAssetQuery.QueryContext(ctx)
|
||||
asset, err := queryAsset.Where(
|
||||
tblAsset.TenantID.Eq(tenantID),
|
||||
tblAsset.ID.Eq(claims.AssetID),
|
||||
tblAsset.DeletedAt.IsNull(),
|
||||
).First()
|
||||
if err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", errorx.ErrRecordNotFound.WithMsg("media asset not found")
|
||||
}
|
||||
@@ -140,16 +142,13 @@ func (s *mediaDelivery) ResolvePlayRedirect(ctx context.Context, tenantID int64,
|
||||
}
|
||||
|
||||
// 二次校验:token 必须对应“该内容 + 该角色”的绑定关系,避免 token 被滥用到非预期内容。
|
||||
var ca models.ContentAsset
|
||||
if err := _db.WithContext(ctx).
|
||||
Where(
|
||||
"tenant_id = ? AND content_id = ? AND asset_id = ? AND role = ?",
|
||||
tenantID,
|
||||
claims.ContentID,
|
||||
claims.AssetID,
|
||||
claims.Role,
|
||||
).
|
||||
First(&ca).Error; err != nil {
|
||||
tblCA, queryCA := models.ContentAssetQuery.QueryContext(ctx)
|
||||
if _, err := queryCA.Where(
|
||||
tblCA.TenantID.Eq(tenantID),
|
||||
tblCA.ContentID.Eq(claims.ContentID),
|
||||
tblCA.AssetID.Eq(claims.AssetID),
|
||||
tblCA.Role.Eq(claims.Role),
|
||||
).First(); err != nil {
|
||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||
return "", errorx.ErrRecordNotFound.WithMsg("content asset binding not found")
|
||||
}
|
||||
@@ -162,7 +161,6 @@ func (s *mediaDelivery) ResolvePlayRedirect(ctx context.Context, tenantID int64,
|
||||
case "stub":
|
||||
return "", errorx.ErrServiceUnavailable.WithMsg("storage provider not configured")
|
||||
default:
|
||||
_ = types.JSON(asset.Meta) // keep meta referenced for future extensions
|
||||
return "", errorx.ErrServiceUnavailable.WithMsg("storage provider not implemented: " + asset.Provider)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user