refactor(server): 移除已放弃的 Ozon API 直传模块,新增素材删除接口
- 删除 shops/publish/categories/ozon 相关路由、模型、schema 与客户端服务(V2.1 决策放弃 API 直传,改人工上传)
- materials 新增 DELETE /assets/{id}:删除素材记录与本地文件,并同步修正 asset_counts
- 试算页支持单张素材删除,生图弹窗交互微调
- 新增 docs/v2.1/HANDOFF.md 工作交接说明,README 补充索引
This commit is contained in:
@@ -46,10 +46,16 @@ def validate_model(provider_name: str, model: str | None) -> None:
|
||||
raise ValueError(f"不支持的模型: {model}(rightapi 支持: {RIGHTAPI_MODELS})")
|
||||
|
||||
|
||||
async def append_generated_asset(product_id: str, image: TaskImage) -> str | None:
|
||||
async def append_generated_asset(
|
||||
product_id: str,
|
||||
image: TaskImage,
|
||||
after_asset_id: str | None = None,
|
||||
) -> str | None:
|
||||
"""把一张生成完成的图追加为 product_assets(generated),并累加 asset_counts。返回 asset_id。
|
||||
|
||||
作为 run_suite 的逐张回调使用(签名须为 (image)),调用方用 partial 绑定 product_id。
|
||||
after_asset_id:插入锚点——新素材排在锚点之后(其余素材顺次后移),方便与原图对比;
|
||||
缺省/锚点无效时追加到组尾。作为 run_suite 的逐张回调使用时签名须为 (image),
|
||||
调用方用 partial 绑定 product_id。
|
||||
"""
|
||||
from sqlalchemy import func, select
|
||||
|
||||
@@ -58,17 +64,41 @@ async def append_generated_asset(product_id: str, image: TaskImage) -> str | Non
|
||||
|
||||
pid = uuid.UUID(product_id)
|
||||
async with get_session_factory()() as db:
|
||||
count = await db.scalar(
|
||||
select(func.count(ProductAsset.id)).where(
|
||||
ProductAsset.product_id == pid,
|
||||
ProductAsset.group_key == "generated",
|
||||
sort_order: int | None = None
|
||||
if after_asset_id:
|
||||
try:
|
||||
anchor = await db.get(ProductAsset, UUID(after_asset_id))
|
||||
except ValueError:
|
||||
anchor = None
|
||||
if anchor is not None and anchor.product_id == pid and anchor.group_key == "generated":
|
||||
# 锚点之后的素材顺次后移,腾出插入位
|
||||
followers = (
|
||||
await db.scalars(
|
||||
select(ProductAsset).where(
|
||||
ProductAsset.product_id == pid,
|
||||
ProductAsset.group_key == "generated",
|
||||
ProductAsset.sort_order > anchor.sort_order,
|
||||
)
|
||||
)
|
||||
).scalars().all()
|
||||
for follower in followers:
|
||||
follower.sort_order += 1
|
||||
sort_order = anchor.sort_order + 1
|
||||
|
||||
if sort_order is None:
|
||||
sort_order = await db.scalar(
|
||||
select(func.coalesce(func.max(ProductAsset.sort_order), -1)).where(
|
||||
ProductAsset.product_id == pid,
|
||||
ProductAsset.group_key == "generated",
|
||||
)
|
||||
)
|
||||
)
|
||||
sort_order = (sort_order or 0) + 1
|
||||
|
||||
asset = ProductAsset(
|
||||
product_id=pid,
|
||||
group_key="generated",
|
||||
variant_name=None,
|
||||
sort_order=count or 0,
|
||||
sort_order=sort_order,
|
||||
type="img",
|
||||
source_url="",
|
||||
stored_url=image.url,
|
||||
|
||||
Reference in New Issue
Block a user