From 837bd4df76712f85700b2985cb30cb2f9dede096 Mon Sep 17 00:00:00 2001 From: zhengshunjin <2667579369@qq.com> Date: Fri, 14 Aug 2026 19:07:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(book):=20=E4=BF=AE=E5=A4=8D=E4=B9=A6?= =?UTF-8?q?=E7=B1=8D=E4=B8=8B=E8=BD=BD=E6=9C=8D=E5=8A=A1=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=B1=BB=E5=9E=8B=E9=AA=8C=E8=AF=81=E5=92=8C?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加 application/vnd.rar 到允许的内容类型列表 - 在响应中添加 raise_for_status() 以处理 HTTP 错误 - 添加 Content-Type 打印用于调试目的 - 改进文件类型验证逻辑 --- app/services/book_service.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/services/book_service.py b/app/services/book_service.py index 234b7ed..5400418 100644 --- a/app/services/book_service.py +++ b/app/services/book_service.py @@ -11,7 +11,7 @@ from app.models import Setting class BookService: ALLOWED_CONTENT_TYPES = ['"application/octet-stream"', "application/octet-stream", "text/plain", - "application/zip"] + "application/zip", "application/vnd.rar"] def __init__(self): setting_record = Setting.query.filter_by(name="book_download").first() @@ -103,10 +103,12 @@ class BookService: print(f'跳转页面了:{file_url}') response = self.session.get(file_url, headers={"referer": file_url}, stream=True) print(f"下载状态码:{response.status_code} {file_url}") + response.raise_for_status() print(dir_name + "/" + file_name) content_type = response.headers.get('Content-Type', '') if content_type not in self.ALLOWED_CONTENT_TYPES: yield f"event: mes_error\ndata: {self.setting['targetDate']} {file_name}\n\n" + print(content_type) print("不是可下载文件") return target_dir = self.download_path / self.setting["targetDate"] / dir_name / file_name