mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-09-07 08:46:37 +08:00
Merge pull request #235 from lins05/support-set-admin-session-expire
This commit is contained in:
@@ -177,6 +177,7 @@ app/
|
|||||||
| `API_KEYS` | **Required**, list of Gemini API keys | `[]` |
|
| `API_KEYS` | **Required**, list of Gemini API keys | `[]` |
|
||||||
| `ALLOWED_TOKENS` | **Required**, list of access tokens | `[]` |
|
| `ALLOWED_TOKENS` | **Required**, list of access tokens | `[]` |
|
||||||
| `AUTH_TOKEN` | Super admin token, defaults to the first of `ALLOWED_TOKENS` | `sk-123456` |
|
| `AUTH_TOKEN` | Super admin token, defaults to the first of `ALLOWED_TOKENS` | `sk-123456` |
|
||||||
|
| `ADMIN_SESSION_EXPIRE` | Admin session expiration time in seconds (5 minutes to 24 hours) | `3600` |
|
||||||
| `TEST_MODEL` | Model for testing key validity | `gemini-1.5-flash` |
|
| `TEST_MODEL` | Model for testing key validity | `gemini-1.5-flash` |
|
||||||
| `IMAGE_MODELS` | Models supporting image generation | `["gemini-2.0-flash-exp"]` |
|
| `IMAGE_MODELS` | Models supporting image generation | `["gemini-2.0-flash-exp"]` |
|
||||||
| `SEARCH_MODELS` | Models supporting web search | `["gemini-2.0-flash-exp"]` |
|
| `SEARCH_MODELS` | Models supporting web search | `["gemini-2.0-flash-exp"]` |
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import datetime
|
|||||||
import json
|
import json
|
||||||
from typing import Any, Dict, List, Type, get_args, get_origin
|
from typing import Any, Dict, List, Type, get_args, get_origin
|
||||||
|
|
||||||
from pydantic import ValidationError, ValidationInfo, field_validator
|
from pydantic import ValidationError, ValidationInfo, field_validator, Field
|
||||||
from pydantic_settings import BaseSettings
|
from pydantic_settings import BaseSettings
|
||||||
from sqlalchemy import insert, select, update
|
from sqlalchemy import insert, select, update
|
||||||
|
|
||||||
@@ -131,6 +131,14 @@ class Settings(BaseSettings):
|
|||||||
FILES_CLEANUP_INTERVAL_HOURS: int = 1
|
FILES_CLEANUP_INTERVAL_HOURS: int = 1
|
||||||
FILES_USER_ISOLATION_ENABLED: bool = True
|
FILES_USER_ISOLATION_ENABLED: bool = True
|
||||||
|
|
||||||
|
# Admin Session Configuration
|
||||||
|
ADMIN_SESSION_EXPIRE: int = Field(
|
||||||
|
default=3600,
|
||||||
|
ge=300,
|
||||||
|
le=86400,
|
||||||
|
description="Admin session expiration time in seconds (5 minutes to 24 hours)"
|
||||||
|
)
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
# 设置默认AUTH_TOKEN(如果未提供)
|
# 设置默认AUTH_TOKEN(如果未提供)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ from fastapi.responses import HTMLResponse, RedirectResponse
|
|||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
|
|
||||||
from app.core.security import verify_auth_token
|
from app.core.security import verify_auth_token
|
||||||
|
from app.config.config import settings
|
||||||
from app.log.logger import get_routes_logger
|
from app.log.logger import get_routes_logger
|
||||||
from app.router import error_log_routes, gemini_routes, openai_routes, config_routes, scheduler_routes, stats_routes, version_routes, openai_compatiable_routes, vertex_express_routes, files_routes
|
from app.router import error_log_routes, gemini_routes, openai_routes, config_routes, scheduler_routes, stats_routes, version_routes, openai_compatiable_routes, vertex_express_routes, files_routes
|
||||||
from app.service.key.key_manager import get_key_manager_instance
|
from app.service.key.key_manager import get_key_manager_instance
|
||||||
@@ -69,7 +70,7 @@ def setup_page_routes(app: FastAPI) -> None:
|
|||||||
logger.info("Successful authentication")
|
logger.info("Successful authentication")
|
||||||
response = RedirectResponse(url="/config", status_code=302)
|
response = RedirectResponse(url="/config", status_code=302)
|
||||||
response.set_cookie(
|
response.set_cookie(
|
||||||
key="auth_token", value=auth_token, httponly=True, max_age=3600
|
key="auth_token", value=auth_token, httponly=True, max_age=settings.ADMIN_SESSION_EXPIRE
|
||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
logger.warning("Failed authentication attempt with invalid token")
|
logger.warning("Failed authentication attempt with invalid token")
|
||||||
|
|||||||
Reference in New Issue
Block a user