From 84d9b7f157bad018281af90fc31c924c93a7d457 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A2=A6=E5=87=8C=E6=B1=90?= Date: Thu, 5 Jun 2025 11:55:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E4=BA=86NSFW=E9=98=88?= =?UTF-8?q?=E5=80=BC=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 1 + config.py | 1 + routes/images.py | 4 ++-- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ee2711d..620b2a0 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ CatismImage 是一个基于Web的图片存储和管理系统,提供用户友 # NSFW过滤配置(目前支持NSFWPY) ENABLE_NSFW_FILTER=true/false NSFWPY_ENDPOINT=your_nsfwpy_endpoint + NSFWPY_THRESHOLD=0.5 ``` 6. 运行后端服务: diff --git a/config.py b/config.py index 69c084d..05374e4 100644 --- a/config.py +++ b/config.py @@ -18,6 +18,7 @@ class Config: ENABLE_NSFW_FILTER = os.getenv('ENABLE_NSFW_FILTER') NSFWPY_ENDPOINT = os.getenv('NSFWPY_ENDPOINT') + NSFWPY_THRESHOLD = os.getenv('NSFWPY_THRESHOLD') if(S3_ACCESS_KEY == None or S3_SECRET_KEY == None or S3_BUCKET == None or S3_ENDPOINT == None): print("错误:缺少必需的S3环境变量") diff --git a/routes/images.py b/routes/images.py index 2316703..c326668 100644 --- a/routes/images.py +++ b/routes/images.py @@ -77,8 +77,8 @@ def upload_image(): nsfw_data = response.json() # 检查NSFW评分 - if nsfw_data.get('neutral', 0) + nsfw_data.get('drawing', 0) < 0.5: - return jsonify({'error': '图片内容不符合安全标准'}), 403 + if nsfw_data.get('neutral', 0) + nsfw_data.get('drawing', 0) < 1 - AppConfig.NSFWPY_THRESHOLD: + return jsonify({'error': '图片内容未通过NSFW检查'}), 403 file.seek(0) except Exception as e: