mirror of
https://github.com/MeowLynxSea/CatismImage.git
synced 2025-07-09 10:54:35 +00:00
修复上传图片校验失败的问题
This commit is contained in:
parent
7d79e4a3c9
commit
7c6eed2022
@ -26,7 +26,7 @@ CatismImage 是一个基于Web的图片存储和管理系统,提供用户友
|
||||
4. [可选] 配置NSFWPY
|
||||
|
||||
如果您希望启用NSFW过滤功能,您需要配置NSFWPY。
|
||||
|
||||
|
||||
请参考[HG-ha/nsfwpy](https://github.com/HG-ha/nsfwpy),通过您喜欢的方式完成配置。
|
||||
|
||||
5. 配置环境变量:
|
||||
|
Binary file not shown.
@ -60,30 +60,30 @@ def upload_image():
|
||||
file.seek(0)
|
||||
except Exception:
|
||||
return jsonify({'error': '无效的图片文件'}), 400
|
||||
|
||||
# 如果启用了NSFW检查
|
||||
if AppConfig.ENABLE_NSFW_FILTER:
|
||||
print("NSFW检查已启用")
|
||||
file.seek(0)
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{AppConfig.NSFWPY_ENDPOINT}/classify",
|
||||
files={'image': file},
|
||||
headers={'accept': 'application/json'}
|
||||
)
|
||||
response.raise_for_status()
|
||||
nsfw_data = response.json()
|
||||
|
||||
# 检查NSFW评分
|
||||
if nsfw_data.get('neutral', 0) + nsfw_data.get('drawing', 0) < 0.5:
|
||||
return jsonify({'error': '图片内容不符合安全标准'}), 403
|
||||
|
||||
file.seek(0)
|
||||
except Exception as e:
|
||||
return jsonify({'error': f'NSFW检查失败: {str(e)}'}), 500
|
||||
except Exception:
|
||||
return jsonify({'error': '无效的图片文件'}), 400
|
||||
|
||||
# 如果启用了NSFW检查
|
||||
if AppConfig.ENABLE_NSFW_FILTER:
|
||||
print("NSFW检查已启用")
|
||||
file.seek(0)
|
||||
try:
|
||||
response = requests.post(
|
||||
f"{AppConfig.NSFWPY_ENDPOINT}/classify",
|
||||
files={'image': file},
|
||||
headers={'accept': 'application/json'}
|
||||
)
|
||||
response.raise_for_status()
|
||||
nsfw_data = response.json()
|
||||
|
||||
# 检查NSFW评分
|
||||
if nsfw_data.get('neutral', 0) + nsfw_data.get('drawing', 0) < 0.5:
|
||||
return jsonify({'error': '图片内容不符合安全标准'}), 403
|
||||
|
||||
file.seek(0)
|
||||
except Exception as e:
|
||||
return jsonify({'error': f'NSFW检查失败: {str(e)}'}), 500
|
||||
|
||||
# 获取文件大小并检查存储空间
|
||||
file.seek(0, 2) # 移动到文件末尾
|
||||
file_size = file.tell() # 获取文件大小(字节)
|
||||
|
Loading…
Reference in New Issue
Block a user