diff --git a/backend/app/workers/packaging_task.py b/backend/app/workers/packaging_task.py index 1c3ed08..b95d274 100644 --- a/backend/app/workers/packaging_task.py +++ b/backend/app/workers/packaging_task.py @@ -61,12 +61,12 @@ def build_delivery_package(self, package_id: int) -> dict: img_bytes = b"" if ic.url: path = ic.url - if os.path.isabs(path): - pass - elif path.startswith("/uploads/"): + if path.startswith("/uploads/"): path = f"{upload_root}/{path.removeprefix('/uploads/')}" elif path.startswith("uploads/"): path = f"{upload_root}/{path.removeprefix('uploads/')}" + elif os.path.isabs(path): + pass try: with open(path, "rb") as f: img_bytes = f.read() @@ -101,6 +101,8 @@ def build_delivery_package(self, package_id: int) -> dict: notes = [] for idx, (_strategy, slot) in enumerate(groups.items()): images_data = [_read_image(slot[k]) for k in sorted(slot)] + if not any(img.get("data") for img in images_data): + raise ValueError(f"套{_strategy}图片文件读取失败,拒绝生成无图交付包") # 配对优先级:①同 strategy 文案精准对齐 ②无同套则按顺序取无套文案 # ③再兜底用第 idx 条/第 1 条,确保每组图都有文案不漏。 tc = texts_by_strategy.get(_strategy)