Fix memoir image delivery and Android rendering
This commit is contained in:
@@ -13,6 +13,7 @@ from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, PageBreak,
|
||||
from reportlab.pdfbase import pdfmetrics
|
||||
from reportlab.pdfbase.cidfonts import UnicodeCIDFont
|
||||
from io import BytesIO
|
||||
from services.memoir_images.storage import TencentCosStorageService, resolve_image_storage_key
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -42,6 +43,23 @@ def split_content_blocks(content: str, images: list[dict]) -> list[dict]:
|
||||
return blocks
|
||||
|
||||
|
||||
def _prepare_pdf_image_assets(images: list[dict]) -> list[dict]:
|
||||
storage = TencentCosStorageService.from_env()
|
||||
prepared_assets: list[dict] = []
|
||||
|
||||
for item in images or []:
|
||||
asset = dict(item)
|
||||
storage_key = resolve_image_storage_key(asset)
|
||||
if asset.get("status") == "completed" and storage_key:
|
||||
try:
|
||||
asset["url"] = storage.get_download_url(storage_key)
|
||||
except Exception as exc:
|
||||
logger.warning(f"PDF 图片签名失败: key={storage_key}, error={exc}")
|
||||
prepared_assets.append(asset)
|
||||
|
||||
return prepared_assets
|
||||
|
||||
|
||||
class PDFService:
|
||||
"""PDF 生成服务"""
|
||||
|
||||
@@ -108,7 +126,7 @@ class PDFService:
|
||||
story.append(Paragraph(chapter.title, heading_style))
|
||||
story.append(Spacer(1, 0.2 * inch))
|
||||
|
||||
images = getattr(chapter, "images", None) or []
|
||||
images = _prepare_pdf_image_assets(getattr(chapter, "images", None) or [])
|
||||
blocks = split_content_blocks(chapter.content, images)
|
||||
|
||||
for block in blocks:
|
||||
|
||||
Reference in New Issue
Block a user