v1.5.7 login.html

This commit is contained in:
lanqian528 2024-10-27 01:13:46 +08:00
parent a34af874c1
commit d638677cc7
7 changed files with 105 additions and 18 deletions

View File

@ -37,7 +37,7 @@ jobs:
images: lanqian528/chat2api
tags: |
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=v1.5.6
type=raw,value=v1.5.7
- name: Build and push
uses: docker/build-push-action@v5

View File

@ -28,7 +28,7 @@
## 功能
### 最新版 v1.5.6
### 最新版 v1.5.7
> 已完成
> - [x] 流式、非流式传输

View File

@ -134,16 +134,17 @@ async def error_tokens():
if enable_gateway:
@app.get("/", response_class=HTMLResponse)
async def chatgpt(request: Request):
seed_token = request.query_params.get("seed")
if not seed_token:
seed_token = request.cookies.get("seed_token")
if not seed_token:
seed_token = str(int(time.time()))
req_token = get_req_token(seed_token)
token = request.query_params.get("token")
if not token:
token = request.cookies.get("token")
if not token:
response = templates.TemplateResponse("login.html", {"request": request})
return response
req_token = get_req_token(token)
seed_token = await verify_token(req_token)
response = templates.TemplateResponse("chatgpt.html", {"request": request, "access_token": seed_token})
response.set_cookie("seed_token", value=seed_token)
response = templates.TemplateResponse("chatgpt.html", {"request": request, "token": token})
response.set_cookie("token", value=seed_token)
return response
@ -224,7 +225,9 @@ if enable_gateway:
for redirect_path in redirect_paths:
if redirect_path in path:
redirect_url = str(request.base_url)
return RedirectResponse(url=f"{redirect_url}?seed={int(time.time())}", status_code=302)
response = RedirectResponse(url=f"{redirect_url}", status_code=302)
response.delete_cookie("token")
return response
return await chatgpt_reverse_proxy(request, path)
else:

View File

@ -101,14 +101,14 @@ async def chatgpt_reverse_proxy(request: Request, path: str):
"sec-fetch-site": "same-origin",
})
seed_token = headers.get("authorization", "").replace("Bearer ", "")
if seed_token:
req_token = get_req_token(seed_token)
token = headers.get("authorization", "").replace("Bearer ", "")
if token:
req_token = get_req_token(token)
access_token = await verify_token(req_token)
if access_token.startswith("eyJhbGciOi"):
headers.update({"authorization": access_token})
else:
req_token = get_req_token(None, seed_token)
req_token = get_req_token(None, token)
access_token = await verify_token(req_token)
headers.update({"authorization": access_token})
else:

View File

@ -4309,7 +4309,7 @@
"queryKey": ["session"],
"state": {
"data": {
"accessToken": "{{ access_token }}",
"accessToken": "{{ token }}",
"authProvider": "login-web",
"user": {}
},
@ -4329,7 +4329,7 @@
},
"isAndroidChrome": false,
"isElectron": false,
"isIos": false
"isIos": true
},
"routes/_conversation": {
"prefetchSearch": null

84
templates/login.html Normal file
View File

@ -0,0 +1,84 @@
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>登录</title>
<script src="https://cdn.tailwindcss.com"></script>
<style>
#popup {
display: none;
}
</style>
</head>
<body class="bg-gradient-to-br from-blue-300 via-indigo-300 to-purple-400 min-h-screen flex items-center justify-center">
<div class="bg-white p-8 rounded-xl shadow-2xl w-96 max-w-md">
<h2 class="text-3xl font-bold text-center text-gray-800 mb-4">登录</h2>
<button
type="button"
onclick="openPopup()"
class="w-full bg-gradient-to-r from-indigo-500 to-blue-500 text-white font-bold py-3 px-4 rounded-lg hover:opacity-90 transition duration-200 ease-in-out"
>
RefreshToken / AccessToken
</button>
<p class="text-xs text-gray-500 text-center mt-4">
<span class="font-semibold text-gray-800">
<span class="font-bold text-indigo-600">RT</span>
<span class="font-bold text-indigo-600">AT</span>
的输入,将作为</span>
<span class="font-bold text-indigo-600">Seed</span>
<span class="font-semibold text-gray-800">随机抽取后台账号</span>
</p>
</div>
<div id="popup" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center">
<div class="bg-white p-8 rounded-xl shadow-lg max-w-lg w-full h-auto">
<h3 class="text-xl font-bold text-gray-800 mb-4 text-center">请输入您的 Token</h3>
<label for="popup-input"></label>
<textarea
id="popup-input"
name="token"
placeholder="RefreshToken / AccessToken / SeedToken"
class="w-full h-56 px-4 py-4 text-md rounded-md bg-gray-100 border-gray-300 focus:border-indigo-500 focus:bg-white focus:ring-2 focus:ring-indigo-200 text-gray-800 transition duration-200 ease-in-out mb-4"
style="resize: none;"
></textarea>
<div class="flex justify-center space-x-4">
<button
onclick="submitToken()"
class="bg-indigo-500 hover:bg-indigo-600 text-white font-bold py-2 px-4 rounded-lg transition duration-200 ease-in-out"
>
开 始
</button>
<button
onclick="closePopup()"
class="bg-gray-300 hover:bg-gray-400 text-gray-800 font-bold py-2 px-4 rounded-lg transition duration-200 ease-in-out"
>
取 消
</button>
</div>
</div>
</div>
<script>
function openPopup() {
document.getElementById('popup').style.display = 'flex';
}
function closePopup() {
document.getElementById('popup').style.display = 'none';
}
function submitToken() {
var inputValue = document.getElementById('popup-input').value;
if (inputValue) {
window.location.href = '/?token=' + inputValue;
closePopup();
} else {
window.location.href = '/?token=' + Math.random().toString(36);
closePopup();
}
}
</script>
</body>
</html>

View File

@ -52,7 +52,7 @@ proxy_url_list = proxy_url.split(',') if proxy_url else []
user_agents_list = ast.literal_eval(user_agents)
logger.info("-" * 60)
logger.info("Chat2Api 1.5.6 | https://github.com/lanqian528/chat2api")
logger.info("Chat2Api 1.5.7 | https://github.com/lanqian528/chat2api")
logger.info("-" * 60)
logger.info("Environment variables:")
logger.info("API_PREFIX: " + str(api_prefix))