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
Binary file not shown.
@ -60,30 +60,30 @@ def upload_image():
|
|||||||
file.seek(0)
|
file.seek(0)
|
||||||
except Exception:
|
except Exception:
|
||||||
return jsonify({'error': '无效的图片文件'}), 400
|
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:
|
except Exception:
|
||||||
return jsonify({'error': '无效的图片文件'}), 400
|
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.seek(0, 2) # 移动到文件末尾
|
||||||
file_size = file.tell() # 获取文件大小(字节)
|
file_size = file.tell() # 获取文件大小(字节)
|
||||||
|
Loading…
Reference in New Issue
Block a user