Files
quyun-v2/backend/database/models/media_assets.gen.go
Rogee 2cc823d3a8 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.
2025-12-22 19:27:31 +08:00

76 lines
6.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
// Code generated by go.ipao.vip/gen. DO NOT EDIT.
package models
import (
"context"
"time"
"quyun/v2/pkg/consts"
"go.ipao.vip/gen"
"go.ipao.vip/gen/types"
"gorm.io/gorm"
)
const TableNameMediaAsset = "media_assets"
// MediaAsset mapped from table <media_assets>
type MediaAsset struct {
ID int64 `gorm:"column:id;type:bigint;primaryKey;autoIncrement:true;comment:主键ID自增仅用于内部关联" json:"id"` // 主键ID自增仅用于内部关联
TenantID int64 `gorm:"column:tenant_id;type:bigint;not null;comment:租户ID多租户隔离关键字段所有查询/写入必须限定 tenant_id" json:"tenant_id"` // 租户ID多租户隔离关键字段所有查询/写入必须限定 tenant_id
UserID int64 `gorm:"column:user_id;type:bigint;not null;comment:用户ID资源上传者用于审计与权限控制" json:"user_id"` // 用户ID资源上传者用于审计与权限控制
Type consts.MediaAssetType `gorm:"column:type;type:character varying(32);not null;default:video;comment:资源类型video/audio/image决定后续处理流程转码/缩略图/封面等)" json:"type"` // 资源类型video/audio/image决定后续处理流程转码/缩略图/封面等)
Status consts.MediaAssetStatus `gorm:"column:status;type:character varying(32);not null;default:uploaded;comment:处理状态uploaded/processing/ready/failed/deletedready 才可被内容引用对外提供" json:"status"` // 处理状态uploaded/processing/ready/failed/deletedready 才可被内容引用对外提供
Provider string `gorm:"column:provider;type:character varying(64);not null;comment:存储提供方:例如 s3/minio/oss便于多存储扩展" json:"provider"` // 存储提供方:例如 s3/minio/oss便于多存储扩展
Bucket string `gorm:"column:bucket;type:character varying(128);not null;comment:存储桶:对象所在 bucket与 provider 组合确定存储定位" json:"bucket"` // 存储桶:对象所在 bucket与 provider 组合确定存储定位
ObjectKey string `gorm:"column:object_key;type:character varying(512);not null;comment:对象键:对象在 bucket 内的 key不得暴露可长期复用的直链通过签名URL/token下发" json:"object_key"` // 对象键:对象在 bucket 内的 key不得暴露可长期复用的直链通过签名URL/token下发
Meta types.JSON `gorm:"column:meta;type:jsonb;not null;default:{};comment:元数据JSON包含 hash、duration、width、height、bitrate、codec 等;用于展示与计费/风控" json:"meta"` // 元数据JSON包含 hash、duration、width、height、bitrate、codec 等;用于展示与计费/风控
DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:timestamp with time zone;comment:软删除时间:非空表示已删除;对外接口需过滤" json:"deleted_at"` // 软删除时间:非空表示已删除;对外接口需过滤
CreatedAt time.Time `gorm:"column:created_at;type:timestamp with time zone;not null;default:now();comment:创建时间:默认 now();用于审计与排序" json:"created_at"` // 创建时间:默认 now();用于审计与排序
UpdatedAt time.Time `gorm:"column:updated_at;type:timestamp with time zone;not null;default:now();comment:更新时间:默认 now();更新状态/元数据时写入" json:"updated_at"` // 更新时间:默认 now();更新状态/元数据时写入
Variant consts.MediaAssetVariant `gorm:"column:variant;type:character varying(32);not null;default:main;comment:产物类型main/preview用于强制试看资源必须绑定独立产物避免用正片绕过" json:"variant"` // 产物类型main/preview用于强制试看资源必须绑定独立产物避免用正片绕过
SourceAssetID int64 `gorm:"column:source_asset_id;type:bigint;comment:派生来源资源IDpreview 产物可指向对应 main 资源;用于建立 preview/main 的 1:1 追溯关系" json:"source_asset_id"` // 派生来源资源IDpreview 产物可指向对应 main 资源;用于建立 preview/main 的 1:1 追溯关系
}
// Quick operations without importing query package
// Update applies changed fields to the database using the default DB.
func (m *MediaAsset) Update(ctx context.Context) (gen.ResultInfo, error) {
return Q.MediaAsset.WithContext(ctx).Updates(m)
}
// Save upserts the model using the default DB.
func (m *MediaAsset) Save(ctx context.Context) error { return Q.MediaAsset.WithContext(ctx).Save(m) }
// Create inserts the model using the default DB.
func (m *MediaAsset) Create(ctx context.Context) error {
return Q.MediaAsset.WithContext(ctx).Create(m)
}
// Delete removes the row represented by the model using the default DB.
func (m *MediaAsset) Delete(ctx context.Context) (gen.ResultInfo, error) {
return Q.MediaAsset.WithContext(ctx).Delete(m)
}
// ForceDelete permanently deletes the row (ignores soft delete) using the default DB.
func (m *MediaAsset) ForceDelete(ctx context.Context) (gen.ResultInfo, error) {
return Q.MediaAsset.WithContext(ctx).Unscoped().Delete(m)
}
// Restore sets deleted_at to NULL for this model's primary key using the default DB.
func (m *MediaAsset) Restore(ctx context.Context) (gen.ResultInfo, error) {
return Q.MediaAsset.WithContext(ctx).RestoreByID(m.ID)
}
// Reload reloads the model from database by its primary key and overwrites current fields.
func (m *MediaAsset) Reload(ctx context.Context) error {
fresh, err := Q.MediaAsset.WithContext(ctx).GetByID(m.ID)
if err != nil {
return err
}
*m = *fresh
return nil
}