Files
quyun-v2/backend/app/http/tenant/dto/media_asset_admin.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

70 lines
3.4 KiB
Go

package dto
import (
"time"
"quyun/v2/pkg/consts"
)
// AdminMediaAssetUploadInitForm defines payload for tenant-admin to initialize a media asset upload.
type AdminMediaAssetUploadInitForm struct {
// Type is the media asset type (video/audio/image).
// Used to decide processing pipeline and validation rules; required.
Type string `json:"type,omitempty"`
// Variant indicates whether this asset is a main or preview product.
// Allowed: main/preview; default is main.
Variant *consts.MediaAssetVariant `json:"variant,omitempty"`
// SourceAssetID links a preview product to its main asset; only meaningful when variant=preview.
SourceAssetID *int64 `json:"source_asset_id,omitempty"`
// ContentType is the MIME type reported by the client (e.g. video/mp4); optional.
// Server should not fully trust it, but can use it as a hint for validation/logging.
ContentType string `json:"content_type,omitempty"`
// FileSize is the expected file size in bytes; optional.
// Used for quota/limit checks and audit; client may omit when unknown.
FileSize int64 `json:"file_size,omitempty"`
// SHA256 is the hex-encoded sha256 of the file; optional.
// Used for deduplication/audit; server may validate it later during upload-complete.
SHA256 string `json:"sha256,omitempty"`
}
// AdminMediaAssetUploadInitResponse returns server-generated upload parameters and the created asset id.
type AdminMediaAssetUploadInitResponse struct {
// AssetID is the created media asset id.
AssetID int64 `json:"asset_id"`
// Provider is the storage provider identifier (e.g. s3/minio/oss/local); for debugging/audit.
Provider string `json:"provider,omitempty"`
// Bucket is the target bucket/container; for debugging/audit (may be empty in stub mode).
Bucket string `json:"bucket,omitempty"`
// ObjectKey is the server-generated object key/path; client must NOT choose it.
ObjectKey string `json:"object_key,omitempty"`
// UploadURL is the URL the client should upload to (signed URL or service endpoint).
UploadURL string `json:"upload_url,omitempty"`
// Headers are additional headers required for upload (e.g. signed headers); optional.
Headers map[string]string `json:"headers,omitempty"`
// FormFields are form fields required for multipart form upload (S3 POST policy); optional.
FormFields map[string]string `json:"form_fields,omitempty"`
// ExpiresAt indicates when UploadURL/FormFields expire; optional.
ExpiresAt *time.Time `json:"expires_at,omitempty"`
}
// AdminMediaAssetUploadCompleteForm defines payload for tenant-admin to mark a media upload as completed.
// This endpoint is expected to be called after the client finishes uploading the object to storage.
type AdminMediaAssetUploadCompleteForm struct {
// ETag is the storage returned ETag (or similar checksum); optional.
// Used for audit/debugging and later integrity verification.
ETag string `json:"etag,omitempty"`
// ContentType is the MIME type observed during upload; optional.
// Server may record it for audit and later processing decisions.
ContentType string `json:"content_type,omitempty"`
// FileSize is the uploaded object size in bytes; optional.
// Server records it for quota/audit and later validation.
FileSize int64 `json:"file_size,omitempty"`
// SHA256 is the hex-encoded sha256 of the uploaded object; optional.
// Server records it for integrity checks/deduplication.
SHA256 string `json:"sha256,omitempty"`
}