docs: 完善文档和清理项目,添加 Gemini 配置指南

主要更新:

📚 文档改进
- 新增 AI_CONFIGURATION.md:详细的 AI 提供商配置指南
- 新增 CHINA_MIRROR_GUIDE.md:中国镜像加速指南
- 删除 6 个过时文档(DEPLOYMENT.md, QUICK_START.md 等)
- 更新 README.md:添加 Gemini 功能特性和 AI 提供商对比表

🧹 脚本清理
- 删除 11 个重复/过时脚本(从 25 个减少到 14 个)
- 删除 PostgreSQL 相关脚本(项目使用 MySQL)
- 删除重复的启动脚本(start_windows.bat, start_app.bat 等)

⚙️ 配置文件更新
- 更新 .env.example:添加 Gemini 配置示例和说明
- 默认 AI_PROVIDER 改为 gemini(推荐)
- 添加各提供商的获取 API Key 链接

🎯 核心改进
- 突出 Gemini 原生 PDF 理解优势
- 提供清晰的 AI 提供商选择指南
- 简化项目结构,提高可维护性

清理内容:
- 删除 docs: DEPLOYMENT.md, DOCKER_MIRROR_SETUP.md, GITHUB_PUSH_GUIDE.md,
  QUICK_START.md, README_QUICKSTART.md, START_HERE.txt
- 删除 scripts: auto_setup_and_run.bat, check_postgres.bat, logs_windows.bat,
  push_to_github.bat, quick_config.bat, restart_docker.bat, setup_docker_mirror.bat,
  start_app.bat, start_postgres.bat, start_windows.bat, start_windows_china.bat

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-12-01 23:21:04 +08:00
parent f403eacb9d
commit ed87aae014
30 changed files with 531 additions and 2206 deletions

View File

@@ -2,10 +2,9 @@ FROM python:3.11-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
# Install system dependencies (gcc for compiling Python packages)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
postgresql-client \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies

32
backend/Dockerfile.china Normal file
View File

@@ -0,0 +1,32 @@
# Dockerfile with China mirrors for faster builds
# Usage: docker build -f Dockerfile.china -t qquiz-backend .
FROM python:3.11-slim
WORKDIR /app
# Use Alibaba Cloud mirror for faster apt-get
RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list.d/debian.sources 2>/dev/null || \
sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list || true
# Install system dependencies (gcc for compiling Python packages)
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt .
# Use Tsinghua PyPI mirror for faster pip install
RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple -r requirements.txt
# Copy application code
COPY . .
# Create uploads directory
RUN mkdir -p uploads
# Expose port
EXPOSE 8000
# Run database migrations and start server
CMD alembic upgrade head && uvicorn main:app --host 0.0.0.0 --port 8000

View File

@@ -28,24 +28,19 @@ async def get_current_user(
headers={"WWW-Authenticate": "Bearer"},
)
print(f"🔍 Received token (first 50 chars): {token[:50] if token else 'None'}...")
# Decode token
payload = decode_access_token(token)
if payload is None:
print(f"❌ Token decode failed - Invalid or expired token")
raise credentials_exception
user_id = payload.get("sub")
if user_id is None:
print(f"❌ No 'sub' in payload: {payload}")
raise credentials_exception
# Convert user_id to int if it's a string
try:
user_id = int(user_id)
except (ValueError, TypeError):
print(f"❌ Invalid user_id format: {user_id}")
raise credentials_exception
# Get user from database
@@ -53,10 +48,8 @@ async def get_current_user(
user = result.scalar_one_or_none()
if user is None:
print(f"❌ User not found with id: {user_id}")
raise credentials_exception
print(f"✅ User authenticated: {user.username} (id={user.id})")
return user

View File

@@ -37,8 +37,6 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -
expire = datetime.utcnow() + timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
to_encode.update({"exp": expire})
print(f"🔑 Creating token with SECRET_KEY (first 20 chars): {SECRET_KEY[:20]}...")
print(f"📦 Token payload: {to_encode}")
encoded_jwt = jwt.encode(to_encode, SECRET_KEY, algorithm=ALGORITHM)
return encoded_jwt
@@ -46,12 +44,9 @@ def create_access_token(data: dict, expires_delta: Optional[timedelta] = None) -
def decode_access_token(token: str) -> Optional[dict]:
"""Decode a JWT access token"""
try:
print(f"🔑 SECRET_KEY (first 20 chars): {SECRET_KEY[:20]}...")
payload = jwt.decode(token, SECRET_KEY, algorithms=[ALGORITHM])
print(f"✅ Token decoded successfully: {payload}")
return payload
except JWTError as e:
print(f"❌ JWT decode error: {type(e).__name__}: {str(e)}")
except JWTError:
return None