From c5f1d6610d7abb10cf44f9dae07e5a4455b37177 Mon Sep 17 00:00:00 2001 From: minecraft1024a Date: Sat, 8 Nov 2025 20:30:11 +0800 Subject: [PATCH] =?UTF-8?q?feat(deps):=20=E5=BC=95=E5=85=A5=20filetype=20?= =?UTF-8?q?=E5=BA=93=E6=9B=BF=E4=BB=A3=E5=BA=9F=E5=BC=83=E7=9A=84=20imghdr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为了应对 Python 3.13 中 `imghdr` 库被废弃的问题,本项目引入 `filetype` 库作为替代方案。 `filetype` 提供了更现代、更可靠的文件类型推断功能。本次更新已将 `content_service.py` 中用于识别图片格式的逻辑从 `imghdr` 切换到 `filetype`,并相应地更新了 `pyproject.toml` 和 `requirements.txt` 依赖文件。 哎呀,`imghdr` 那个老古董总算是要被淘汰了,再不换掉,迟早要变成历史遗留问题。哼,这种事情还得我来提醒主人,真是让人操心。 --- pyproject.toml | 1 + requirements.txt | 1 + .../maizone_refactored/services/content_service.py | 8 ++++---- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 888fe1ad0..c95ceacbd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -19,6 +19,7 @@ dependencies = [ "faiss-cpu>=1.11.0", "fastapi>=0.116.0", "google>=3.0.0", + "filetype>=1.2.0", "google-genai>=1.29.0", "httpx>=0.28.1", "json-repair>=0.47.6", diff --git a/requirements.txt b/requirements.txt index 085915ca3..eb6b499a2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ dotenv faiss-cpu fastapi fastmcp +filetype rjieba jsonlines maim_message diff --git a/src/plugins/built_in/maizone_refactored/services/content_service.py b/src/plugins/built_in/maizone_refactored/services/content_service.py index c302f15e9..f4793477b 100644 --- a/src/plugins/built_in/maizone_refactored/services/content_service.py +++ b/src/plugins/built_in/maizone_refactored/services/content_service.py @@ -6,7 +6,7 @@ import asyncio import base64 import datetime -import imghdr +import filetype from collections.abc import Callable import aiohttp @@ -238,11 +238,11 @@ class ContentService: continue image_bytes = await resp.read() - image_format = imghdr.what(None, image_bytes) - if not image_format: + kind = filetype.guess(image_bytes) + if kind is None: logger.error(f"无法识别图片格式: {image_url}") return None - + image_format = kind.extension image_base64 = base64.b64encode(image_bytes).decode("utf-8") vision_model_name = self.get_config("models.vision_model", "vlm")