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

XFEstudio/gpt4free

Enhance user validation in Api class by adjusting username criteria and ensuring proper formatting with country prefix

046e009e
hlohaus <983577+hlohaus@users.noreply.github.com>
提交于

代码差异

1 个文件 +2 -2
Modified g4f/api/__init__.py +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"