From c7ba0cd3d895d88871ee6e3794d32a99fd4390f1 Mon Sep 17 00:00:00 2001 From: Jackp0t <16182712+jackkp0t@user.noreply.gitee.com> Date: Sat, 24 Oct 2026 15:34:45 +0800 Subject: [PATCH] fix: PDF members inside a zip archive were silently skipped during split PdfSplitHandle.handle read the file with file.chunks(), which only exists on Django UploadedFile. When a PDF arrives as a member of a zip archive it is a zipfile.ZipExtFile, so the call raised AttributeError, which ZipSplitHandle.handle swallowed without logging, and the split API returned an empty result for zips containing only PDFs. Read the buffer through the get_buffer abstraction that every other split handle already uses (it works for both UploadedFile and ZipExtFile), and log the member name and error instead of silently dropping it. --- apps/common/handle/impl/text/pdf_split_handle.py | 4 ++-- apps/common/handle/impl/text/zip_split_handle.py | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/apps/common/handle/impl/text/pdf_split_handle.py b/apps/common/handle/impl/text/pdf_split_handle.py index 3e416285b94..a83d718c6ae 100644 --- a/apps/common/handle/impl/text/pdf_split_handle.py +++ b/apps/common/handle/impl/text/pdf_split_handle.py @@ -58,10 +58,10 @@ def handle( get_buffer, save_image, ): + buffer = get_buffer(file) with tempfile.NamedTemporaryFile(delete=False) as temp_file: # 将上传的文件保存到临时文件中 - for chunk in file.chunks(): - temp_file.write(chunk) + temp_file.write(buffer) # 获取临时文件的路径 temp_file_path = temp_file.name diff --git a/apps/common/handle/impl/text/zip_split_handle.py b/apps/common/handle/impl/text/zip_split_handle.py index 14f1b7c310a..2366e43ea1c 100644 --- a/apps/common/handle/impl/text/zip_split_handle.py +++ b/apps/common/handle/impl/text/zip_split_handle.py @@ -28,6 +28,7 @@ from common.handle.impl.text.xls_split_handle import XlsSplitHandle from common.handle.impl.text.xlsx_split_handle import XlsxSplitHandle from common.utils.common import parse_md_file_link, parse_md_image +from common.utils.logger import maxkb_logger class FileBufferHandle: @@ -170,8 +171,8 @@ def handle(self, file, pattern_list: List, with_filter: bool, limit: int, get_bu result = [*result, *value] else: result.append(value) - except Exception: - pass + except Exception as e: + maxkb_logger.warning(f"Zip member: {file}, split error: {e}") image_list = get_image_list(result, files) result = filter_image_file(result, image_list) image_mode_list = []