XFE Git
XFE Studio Git
Git 首页 全局搜索
XFE 主站 文档 NuGet
公开
关注 0 Fork 0 Star 1
返回提交历史

XFEstudio/gpt4free

Add check fingerprint

17d36d51
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

3 个文件 +8 -10
Modified g4f/Provider/EasyChat.py +1 -1
@@ -22,7 +22,7 @@ class EasyChat(OpenaiTemplate, AuthFileMixin):
22 22 active_by_default = True
23 23 use_model_names = True
24 24
25 default_model = "gpt-oss-120b-free"
25 default_model = DEFAULT_MODEL.split("/")[-1]
26 26 model_aliases = {
27 27 DEFAULT_MODEL: default_model,
28 28 }
Modified g4f/api/__init__.py +0 -4
@@ -261,10 +261,6 @@ class Api:
261 261 if path.startswith("/v1") or path.startswith("/api/") or (AppConfig.demo and path == '/backend-api/v2/upload_cookies'):
262 262 if request.method != "OPTIONS":
263 263 if user_g4f_api_key is None:
264 ip = request.headers.get("X-Forwarded-For", "")[:4].strip(":.")
265 country = request.headers.get("Cf-Ipcountry", "")
266 agent = request.headers.get("User-Agent", "")
267 debug.log(f"User: '{user}' G4F API key is required. IP: {ip}, Country: {country}, User-Agent: {agent}")
268 264 return ErrorResponse.from_message("G4F API key required", HTTP_401_UNAUTHORIZED)
269 265 if AppConfig.g4f_api_key is None and user is None:
270 266 return ErrorResponse.from_message("Invalid G4F API key", HTTP_403_FORBIDDEN)
Modified g4f/gui/server/backend_api.py +7 -5
@@ -110,10 +110,12 @@ class Backend_Api(Api):
110 110 def get_public_key():
111 111 if not has_crypto:
112 112 return jsonify({"error": {"message": "Crypto support is not available"}}), 501
113 # if time.time() - int(base64.b64decode(request.cookies.get("fingerprint", "MA==")).decode()) > 60:
114 # If the fingerprint is older than 60 seconds, generate a new one
115 # resp = jsonify({"error": {"message": "Please refresh the page"}})
116 return resp
113 try:
114 diff = time.time() - int(base64.b64decode(request.cookies.get("fingerprint")).decode())
115 except Exception as e:
116 return jsonify({"error": {"message": "Invalid fingerprint"}}), 403
117 if diff > 60 * 60 * 2:
118 return jsonify({"error": {"message": "Please refresh the page"}}), 403
117 119 # Send the public key to the client for encryption
118 120 return jsonify({
119 121 "public_key": public_key_pem.decode(),
@@ -298,7 +300,7 @@ class Backend_Api(Api):
298 300 @app.route('/backend-api/v2/version', methods=['GET'])
299 301 def version():
300 302 resp = jsonify(self.get_version())
301 resp.set_cookie('fingerprint', base64.b64encode(str(int(time.time())).encode()).decode(), max_age=60, httponly=True, secure=True)
303 resp.set_cookie('fingerprint', base64.b64encode(str(int(time.time())).encode()).decode(), max_age=60 * 60 *2, httponly=True, secure=True)
302 304 return resp
303 305
304 306 @app.route('/backend-api/v2/create', methods=['GET'])