Skip to content

Commit

Permalink
v1.7.0-beta3 fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lanqian528 committed Nov 6, 2024
1 parent 997ea02 commit a0d539c
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 9 deletions.
3 changes: 3 additions & 0 deletions chatgpt/authorization.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ async def verify_token(req_token):
return access_token
elif len(req_token) == 45:
try:
if req_token in globals.error_token_list:
raise HTTPException(status_code=401, detail="Error RefreshToken")

access_token = await rt2ac(req_token, force_refresh=False)
return access_token
except HTTPException as e:
Expand Down
1 change: 0 additions & 1 deletion chatgpt/chatLimit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import threading
import time
from datetime import datetime

Expand Down
28 changes: 21 additions & 7 deletions gateway/share.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json
import random
import time

import jwt
from fastapi import Request, HTTPException, Security
from fastapi.responses import Response
from fastapi.security import HTTPAuthorizationCredentials
Expand Down Expand Up @@ -219,14 +221,17 @@ async def refresh(request: Request):
if not refresh_token and not access_token:
raise HTTPException(status_code=401, detail="refresh_token or access_token is required")

need_refresh = True
if access_token:
account_check_info = await chatgpt_account_check(access_token)
if account_check_info:
auth_info.update(account_check_info)
auth_info.update({"accessToken": access_token})
return Response(content=json.dumps(auth_info), media_type="application/json")

if refresh_token:
try:
access_token_info = jwt.decode(access_token, options={"verify_signature": False})
exp = access_token_info.get("exp", 0)
if exp > int(time.time()) + 60 * 60 * 24 * 5:
need_refresh = False
except Exception as e:
logger.error(f"access_token: {e}")

if refresh_token and need_refresh:
chatgpt_refresh_info = await chatgpt_refresh(refresh_token)
if chatgpt_refresh_info:
auth_info.update(chatgpt_refresh_info)
Expand All @@ -236,4 +241,13 @@ async def refresh(request: Request):
auth_info.update(account_check_info)
auth_info.update({"accessToken": access_token})
return Response(content=json.dumps(auth_info), media_type="application/json")
elif access_token:
account_check_info = await chatgpt_account_check(access_token)
if account_check_info:
auth_info.update(account_check_info)
auth_info.update({"accessToken": access_token})
return Response(content=json.dumps(auth_info), media_type="application/json")

raise HTTPException(status_code=401, detail="Unauthorized")


1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ pybase64
jinja2
APScheduler
ua-generator
pyjwt
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.0-beta2
1.7.0-beta3

0 comments on commit a0d539c

Please sign in to comment.