fix: include images in delivery package
This commit is contained in:
@@ -61,12 +61,12 @@ def build_delivery_package(self, package_id: int) -> dict:
|
|||||||
img_bytes = b""
|
img_bytes = b""
|
||||||
if ic.url:
|
if ic.url:
|
||||||
path = ic.url
|
path = ic.url
|
||||||
if os.path.isabs(path):
|
if path.startswith("/uploads/"):
|
||||||
pass
|
|
||||||
elif path.startswith("/uploads/"):
|
|
||||||
path = f"{upload_root}/{path.removeprefix('/uploads/')}"
|
path = f"{upload_root}/{path.removeprefix('/uploads/')}"
|
||||||
elif path.startswith("uploads/"):
|
elif path.startswith("uploads/"):
|
||||||
path = f"{upload_root}/{path.removeprefix('uploads/')}"
|
path = f"{upload_root}/{path.removeprefix('uploads/')}"
|
||||||
|
elif os.path.isabs(path):
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
img_bytes = f.read()
|
img_bytes = f.read()
|
||||||
@@ -101,6 +101,8 @@ def build_delivery_package(self, package_id: int) -> dict:
|
|||||||
notes = []
|
notes = []
|
||||||
for idx, (_strategy, slot) in enumerate(groups.items()):
|
for idx, (_strategy, slot) in enumerate(groups.items()):
|
||||||
images_data = [_read_image(slot[k]) for k in sorted(slot)]
|
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 文案精准对齐 ②无同套则按顺序取无套文案
|
# 配对优先级:①同 strategy 文案精准对齐 ②无同套则按顺序取无套文案
|
||||||
# ③再兜底用第 idx 条/第 1 条,确保每组图都有文案不漏。
|
# ③再兜底用第 idx 条/第 1 条,确保每组图都有文案不漏。
|
||||||
tc = texts_by_strategy.get(_strategy)
|
tc = texts_by_strategy.get(_strategy)
|
||||||
|
|||||||
Reference in New Issue
Block a user