feat: 优化图片资源删除管理,生图任务列表管理
This commit is contained in:
@@ -134,6 +134,18 @@ async def delete_product(
|
||||
if product is None:
|
||||
raise HTTPException(status_code=404, detail="商品不存在")
|
||||
if hard:
|
||||
# 先阻止后台 Worker 回写新生成素材,再删除已有图片与商品记录。
|
||||
from services.jobs import cancel_product_jobs
|
||||
await cancel_product_jobs(str(product.id))
|
||||
assets = (await db.scalars(
|
||||
select(ProductAsset).where(ProductAsset.product_id == product.id)
|
||||
)).all()
|
||||
try:
|
||||
from services.image_assets import get_image_asset_service
|
||||
|
||||
await get_image_asset_service().delete_product_media(str(product.id), assets)
|
||||
except Exception as exc: # noqa: BLE001
|
||||
raise HTTPException(status_code=502, detail=f"图片存储删除失败,商品未删除:{exc}") from exc
|
||||
await db.delete(product)
|
||||
else:
|
||||
product.stage = Stage.archived
|
||||
@@ -160,6 +172,9 @@ async def list_assets(
|
||||
"type": a.type,
|
||||
"source_url": a.source_url,
|
||||
"stored_url": a.stored_url,
|
||||
"original_url": a.original_url,
|
||||
"watermark_enabled": a.watermark_enabled,
|
||||
"watermark_config": a.watermark_config,
|
||||
"status": a.status.value,
|
||||
"width": a.width,
|
||||
"height": a.height,
|
||||
|
||||
Reference in New Issue
Block a user