Merge pull request #165 from jasonwu1994/feature/add-token-via-get

Add new GET API for adding single token
This commit is contained in:
LanQian 2024-10-27 10:02:36 +08:00 committed by GitHub
commit fde16c87f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -131,6 +131,17 @@ async def error_tokens():
return {"status": "success", "error_tokens": error_tokens_list}
@app.get(f"/{api_prefix}/tokens/add/{{token}}" if api_prefix else "/tokens/add/{token}")
async def add_token(token: str):
if token.strip() and not token.startswith("#"):
globals.token_list.append(token.strip())
with open("data/token.txt", "a", encoding="utf-8") as f:
f.write(token.strip() + "\n")
logger.info(f"Token count: {len(globals.token_list)}, Error token count: {len(globals.error_token_list)}")
tokens_count = len(set(globals.token_list) - set(globals.error_token_list))
return {"status": "success", "tokens_count": tokens_count}
if enable_gateway:
@app.get("/", response_class=HTMLResponse)
async def chatgpt_html(request: Request):