Files

43 lines
2.4 KiB
Python

"""采集素材(图片/视频):分组、源站 URL、转存 URL、状态。"""
from __future__ import annotations
import uuid
from datetime import datetime
from sqlalchemy import Boolean, DateTime, Enum, ForeignKey, Integer, String, Text, Uuid, func
from sqlalchemy.orm import Mapped, mapped_column
from db import Base
from models.enums import AssetStatus
from models.types import JSONType
class ProductAsset(Base):
__tablename__ = "product_assets"
id: Mapped[uuid.UUID] = mapped_column(Uuid(as_uuid=True), primary_key=True, default=uuid.uuid4)
product_id: Mapped[uuid.UUID] = mapped_column(
Uuid(as_uuid=True), ForeignKey("products.id", ondelete="CASCADE"), index=True
)
group_key: Mapped[str] = mapped_column(String(16), default="main") # main/sku/detail/video/param/generated
variant_name: Mapped[str | None] = mapped_column(String(128), nullable=True) # SKU 规格名
sort_order: Mapped[int] = mapped_column(Integer, default=0)
type: Mapped[str] = mapped_column(String(8), default="img") # img / video
source_url: Mapped[str] = mapped_column(Text, default="") # 采集源站地址;生成图旧数据可能存无水印 URL
stored_url: Mapped[str | None] = mapped_column(Text, nullable=True) # 当前展示版 URL(兼容旧接口)
# 图片生命周期:original 始终无水印;当前版用于页面预览、下载、导出。
# 未加水印时 original 与 current 指向同一对象;不保留历史水印版。
original_url: Mapped[str | None] = mapped_column(Text, nullable=True)
original_storage_key: Mapped[str | None] = mapped_column(String(1024), nullable=True)
current_storage_key: Mapped[str | None] = mapped_column(String(1024), nullable=True)
watermark_enabled: Mapped[bool] = mapped_column(Boolean, default=False)
watermark_config: Mapped[dict | None] = mapped_column(JSONType, nullable=True)
status: Mapped[AssetStatus] = mapped_column(
Enum(AssetStatus, native_enum=False, length=16), default=AssetStatus.pending, index=True
)
dedupe_key: Mapped[str | None] = mapped_column(String(512), nullable=True, index=True)
width: Mapped[int | None] = mapped_column(Integer, nullable=True)
height: Mapped[int | None] = mapped_column(Integer, nullable=True)
error: Mapped[str | None] = mapped_column(Text, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())