Files
CI Bot 276342520f
CI/CD Pipeline / Validate Code Quality And Tests (pull_request) Failing after 8s
CI/CD Pipeline / Frontend Lint (pull_request) Successful in 3m28s
CI/CD Pipeline / Build & Push Staging (Watchtower auto-deploy) (pull_request) Has been skipped
CI/CD Pipeline / Build Production Runtime Images (pull_request) Has been skipped
CI/CD Pipeline / Staging E2E Tests (pull_request) Has been skipped
CI/CD Pipeline / Staging API Integration Tests (pull_request) Has been skipped
CI/CD Pipeline / Deploy Production (pull_request) Has been skipped
CI/CD Pipeline / Production Browser E2E (pull_request) Has been skipped
cleanup: Backend Phase 1 — 5项代码清理任务
1. 修复密码重置接口路径不一致 Bug (auth.py)
   - forgot_password 硬编码 localhost → 使用 APP_BASE_URL 配置

2. 删除 8 处死代码(未使用 import/变量)
   - 清理多个文件中的未使用导入和变量

3. 删除 8 个空文件/空模块
   - 删除无内容的 __init__.py 文件

4. 合并 3 对 100% 完全重复的函数
   - 提取 check_project_access/get_user_plan/require_project_and_library
   - 新建 apps/api/app/api/routes/_helpers.py 作为共享模块
   - 6 个路由文件改为从 _helpers 导入

5. 对齐 6 个废弃/异常环境变量
   - 修复 DATABASE_POOL_RECYLE 拼写错误 → DATABASE_POOL_RECYCLE
   - 添加 JWT_ALGORITHM/JWT_ACCESS_TOKEN_EXPIRE_MINUTES/JWT_REFRESH_TOKEN_EXPIRE_DAYS 到 Settings
   - 修复 jwt_service.py hasattr 字段名匹配
   - .env.example: CORS_ORIGINS → CORS_ORIGINS_RAW(逗号分隔格式)
   - .env.example: 启用 APP_ENV
   - 修复 OSS_ENDPOINT 默认值拼写错误 (aliiyuncs.com → aliyuncs.com)
   - 添加 COSYVOICE_* 变量来源注释

修改文件: 52 个(新增 1,删除 8,修改 43)
2026-07-13 13:23:30 +08:00

39 lines
1.2 KiB
Python

"""
Authentication dependency compatibility layer.
Canonical bearer-token parsing lives in app.auth. This module re-exports
common auth dependencies for backward compatibility.
"""
from __future__ import annotations
from app.auth import AuthenticatedUser
from app.auth import get_current_user as get_authenticated_user
from app.dependencies import get_user_repository
from fastapi import Depends, HTTPException
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
from packages.domain.entities import User
from packages.ports.user_repository import UserRepository
optional_bearer_scheme = HTTPBearer(auto_error=False)
async def get_current_user(
authenticated_user: AuthenticatedUser = Depends(get_authenticated_user),
) -> User:
return authenticated_user.user
async def get_current_user_optional(
credentials: HTTPAuthorizationCredentials | None = Depends(optional_bearer_scheme),
user_repository: UserRepository = Depends(get_user_repository),
) -> User | None:
if credentials is None:
return None
try:
authenticated_user = await get_authenticated_user(credentials, user_repository)
except HTTPException:
return None
return authenticated_user.user