Add HTTP exception helpers and update models

Introduced utils/http/http_exceptions.py with common HTTP exception helpers for FastAPI. Updated main.py to use a global exception handler that logs and hides internal errors. Refined models/README.md to document new models and relationships, including PhysicalFile and UploadSession, and updated DTO and enum documentation. Simplified ThemeResponse in models/color.py. Improved models/download.py with type annotations, index changes, and import optimizations. Fixed a parameter type in clean.py.

Co-Authored-By: 砂糖橘 <54745033+Foxerine@users.noreply.github.com>
This commit is contained in:
2025-12-25 15:48:21 +08:00
parent 44a8959aa5
commit 5835b4c626
6 changed files with 301 additions and 76 deletions

View File

@@ -1,5 +1,5 @@
from enum import StrEnum
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Annotated
from uuid import UUID
from sqlmodel import Field, Relationship, UniqueConstraint, Index
@@ -7,6 +7,10 @@ from sqlmodel import Field, Relationship, UniqueConstraint, Index
from .base import SQLModelBase
from .mixin import UUIDTableBaseMixin, TableBaseMixin
if TYPE_CHECKING:
from .user import User
from .task import Task
from .node import Node
class DownloadStatus(StrEnum):
"""下载状态枚举"""
@@ -24,18 +28,12 @@ class DownloadType(StrEnum):
pass
if TYPE_CHECKING:
from .user import User
from .task import Task
from .node import Node
# ==================== Aria2 信息模型 ====================
class DownloadAria2InfoBase(SQLModelBase):
"""Aria2下载信息基础模型"""
info_hash: str | None = Field(default=None, max_length=40)
info_hash: Annotated[str | None, Field(max_length=40)] = None
"""InfoHashBT种子"""
piece_length: int = 0
@@ -118,11 +116,10 @@ class Download(DownloadBase, UUIDTableBaseMixin):
__table_args__ = (
UniqueConstraint("node_id", "g_id", name="uq_download_node_gid"),
Index("ix_download_status", "status"),
Index("ix_download_user_status", "user_id", "status"),
)
status: DownloadStatus = Field(default=DownloadStatus.RUNNING, sa_column_kwargs={"server_default": "'running'"})
status: DownloadStatus = Field(default=DownloadStatus.RUNNING, sa_column_kwargs={"server_default": "'running'"}, index=True)
"""下载状态"""
type: int = Field(default=0, sa_column_kwargs={"server_default": "0"})
@@ -196,5 +193,4 @@ class Download(DownloadBase, UUIDTableBaseMixin):
node: "Node" = Relationship(back_populates="downloads")
"""执行下载的节点"""