Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1868,6 +1868,11 @@ def _parse_llm_response(self, response) -> Dict:

cleaned = _sanitize_llm_json_output(content)
cleaned = _extract_outer_json_value(cleaned)

# ★ 修复 #162:LLM 返回空响应时提前返回友好错误,而非抛 JSONDecodeError
if not cleaned:
raise ValueError("LLM 返回内容为空,无法解析规划数据")

try:
return json.loads(cleaned)
except json.JSONDecodeError:
Expand Down
9 changes: 8 additions & 1 deletion application/core/services/export_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ def export_novel(self, novel_id: str, format: str) -> Tuple[bytes, str, str]:
chapters = self.chapter_repository.list_by_novel(NovelId(novel_id))
chapters.sort(key=lambda x: x.number)
logger.info("导出: %s, 章节数 %s", novel.title, len(chapters))
# ★ 修复 #143:记录每章内容长度,便于排查导出内容为空的问题
for ch_debug in chapters:
ch_len = len(ch_debug.content or "")
if ch_len == 0:
logger.warning("导出警告: 章节 %d (%s) 内容为空", ch_debug.number, ch_debug.title or "无标题")
if format == "epub":
result = self._export_to_epub(novel, chapters)
elif format == "pdf":
Expand Down Expand Up @@ -192,7 +197,9 @@ def _export_to_epub(self, novel: Novel, chapters: list[Chapter]) -> Tuple[bytes,

book.toc = tuple([intro] + spine_items[1:])
book.add_item(epub.EpubNcx())
# 不使用空 EpubNav(ebooklib 生成 nav 时会解析正文,空文档会触发 lxml Document is empty)
# ★ 修复 #143:添加 EpubNav 导航文档(EPUB 3 标准要求)
# 缺失 nav 文档会导致部分阅读器只显示目录而无法加载正文内容
book.add_item(epub.EpubNav())
book.spine = spine_items

tmp_path: Optional[str] = None
Expand Down