⚒️ 重大重构 LoveACE V2

引入了 mongodb
对数据库进行了一定程度的数据加密
性能改善
代码简化
统一错误模型和响应
使用 apifox 作为文档
This commit is contained in:
2025-11-20 20:44:25 +08:00
parent 6b90c6d7bb
commit bbc86b8330
168 changed files with 14264 additions and 19152 deletions

View File

@@ -0,0 +1,46 @@
from fastapi import status
from loveace.router.schemas import ErrorToCode, ErrorToCodeNode
class ProfileErrorToCode(ErrorToCode):
profile_not_found: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_404_NOT_FOUND,
code="PROFILE_NOT_FOUND",
message="用户资料未找到",
)
unauthorized_access: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_401_UNAUTHORIZED,
code="UNAUTHORIZED_ACCESS",
message="未授权的访问",
)
need_one_more_field: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_400_BAD_REQUEST,
code="NEED_ONE_MORE_FIELD",
message="需要至少提供一个字段进行更新",
)
too_large_image: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_413_REQUEST_ENTITY_TOO_LARGE,
code="TOO_LARGE_IMAGE",
message="上传的图片过大",
)
mimetype_not_allowed: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
code="MIMETYPE_NOT_ALLOWED",
message="不支持的图片格式",
)
resource_expired: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_410_GONE,
code="RESOURCE_EXPIRED",
message="资源已过期",
)
remote_service_error: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_502_BAD_GATEWAY,
code="REMOTE_SERVICE_ERROR",
message="远程服务错误",
)
server_error: ErrorToCodeNode = ErrorToCodeNode(
error_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
code="SERVER_ERROR",
message="服务器错误",
)

View File

@@ -0,0 +1,56 @@
from enum import Enum
from typing import Optional
from pydantic import BaseModel, Field
class FlutterImageUploadResponse(BaseModel):
uuid: str = Field(..., description="图片的UUID")
md5: str = Field(..., description="图片的MD5值")
class FlutterProfileResponse(BaseModel):
dark_mode: bool = Field(..., description="是否启用暗黑模式")
light_mode_opacity: float = Field(..., description="浅色模式下的透明度")
light_mode_brightness: float = Field(..., description="浅色模式下的亮度")
light_mode_background_url: Optional[str] = Field(
None, description="浅色模式下的背景图片 URL"
)
light_mode_blur: float = Field(..., description="浅色模式下的背景模糊程度")
dark_mode_opacity: float = Field(..., description="深色模式下的透明度")
dark_mode_brightness: float = Field(..., description="深色模式下的亮度")
dark_mode_background_url: Optional[str] = Field(
None, description="深色模式下的背景图片 URL"
)
dark_mode_background_blur: float = Field(
..., description="深色模式下的背景模糊程度"
)
class FlutterProfileUpdateRequest(BaseModel):
dark_mode: Optional[bool] = Field(None, description="是否启用暗黑模式")
light_mode_opacity: Optional[float] = Field(None, description="浅色模式下的透明度")
light_mode_brightness: Optional[float] = Field(None, description="浅色模式下的亮度")
light_mode_background_uuid: Optional[str] = Field(
None, description="浅色模式下的背景图片 UUID"
)
light_mode_blur: Optional[float] = Field(
None, description="浅色模式下的背景模糊程度"
)
dark_mode_opacity: Optional[float] = Field(None, description="深色模式下的透明度")
dark_mode_brightness: Optional[float] = Field(None, description="深色模式下的亮度")
dark_mode_background_uuid: Optional[str] = Field(
None, description="深色模式下的背景图片 UUID"
)
dark_mode_background_blur: Optional[float] = Field(
None, description="深色模式下的背景模糊程度"
)
class FlutterImageMD5Response(BaseModel):
md5: str = Field(..., description="图片的MD5值")
class FlutterImageMode(Enum):
LIGHT = "light"
DARK = "dark"

View File

@@ -0,0 +1,24 @@
from typing import Optional
from pydantic import BaseModel, Field
class UserProfileUpdateRequest(BaseModel):
nickname: Optional[str] = Field(..., description="用户昵称")
slogan: Optional[str] = Field(..., description="用户个性签名")
avatar_uuid: Optional[str] = Field(..., description="用户头像UUID")
class UserProfileResponse(BaseModel):
nickname: str = Field(..., description="用户昵称")
slogan: str = Field(..., description="用户个性签名")
avatar_url: str = Field(..., description="用户头像URL")
class AvatarUpdateResponse(BaseModel):
uuid: str = Field(..., description="新的头像UUID")
md5: str = Field(..., description="头像文件的MD5值")
class AvatarMD5Response(BaseModel):
md5: str = Field(..., description="用户头像的MD5值")

View File

@@ -0,0 +1,8 @@
from pydantic import BaseModel, Field
class Uuid2S3KeyCache(BaseModel):
"""UUID 到 S3 Key 的缓存模型"""
s3_key: str = Field(..., description="S3对象的key")
md5: str = Field(..., description="文件的MD5值")