返回提交历史
Modified
g4f/api/__init__.py
+2
-2
XFEstudio/gpt4free
Enhance user validation in Api class by adjusting username criteria and ensuring proper formatting with country prefix
046e009e
代码差异
1 个文件
+2
-2
@@ -258,6 +258,7 @@ class Api:
258
258
raise ValueError("User not found")
259
259
except:
260
260
return ErrorResponse.from_message(f"Invalid G4F API key", HTTP_401_UNAUTHORIZED)
261
user = f"{country}:{user}" if country else user
261
262
expires = int(expires) - int(time.time())
262
263
hours, remainder = divmod(expires, 3600)
263
264
minutes, seconds = divmod(remainder, 60)
@@ -268,10 +269,9 @@ class Api:
268
269
for char in user:
269
270
if char.isupper():
270
271
count += 1
271
if count > 4:
272
if count >= 6:
272
273
debug.log(f"Invalid user name (screaming): '{user}'")
273
274
return ErrorResponse.from_message("Invalid user name (screaming)", HTTP_401_UNAUTHORIZED)
274
user = f"{country}:{user}" if country else user
275
275
debug.log(f"User: '{user}' G4F API key expires in {hours}h {minutes}m {seconds}s")
276
276
else:
277
277
user = "admin"