38 lines
818 B
Python
38 lines
818 B
Python
|
|
"""Asset repository — 资源表数据访问。"""
|
||
|
|
|
||
|
|
import uuid
|
||
|
|
|
||
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
|
|
||
|
|
from app.features.asset.models import Asset
|
||
|
|
|
||
|
|
|
||
|
|
def _new_id() -> str:
|
||
|
|
return str(uuid.uuid4())
|
||
|
|
|
||
|
|
|
||
|
|
async def create_asset(
|
||
|
|
db: AsyncSession,
|
||
|
|
*,
|
||
|
|
asset_type: str,
|
||
|
|
storage_key: str,
|
||
|
|
url: str | None = None,
|
||
|
|
provider: str | None = None,
|
||
|
|
style_profile: str | None = None,
|
||
|
|
prompt_final: str | None = None,
|
||
|
|
status: str = "completed",
|
||
|
|
) -> Asset:
|
||
|
|
"""Create asset. Caller must commit."""
|
||
|
|
asset = Asset(
|
||
|
|
id=_new_id(),
|
||
|
|
asset_type=asset_type,
|
||
|
|
storage_key=storage_key,
|
||
|
|
url=url,
|
||
|
|
provider=provider,
|
||
|
|
style_profile=style_profile,
|
||
|
|
prompt_final=prompt_final,
|
||
|
|
status=status,
|
||
|
|
)
|
||
|
|
db.add(asset)
|
||
|
|
return asset
|