feat: 合并 File 和 Folder 模型为统一的 Object 模型,优化对象管理逻辑

refactor: 更新相关模型和路由以支持新对象模型,移除冗余代码
This commit is contained in:
2025-12-18 17:18:40 +08:00
parent d271c81de7
commit 68343c710b
12 changed files with 420 additions and 153 deletions

View File

@@ -1,24 +1,29 @@
from typing import TYPE_CHECKING, Optional
from typing import TYPE_CHECKING
from sqlmodel import Field, Relationship, Index
from .base import TableBase
from datetime import datetime
if TYPE_CHECKING:
from .file import File
from .object import Object
class SourceLink(TableBase, table=True):
"""链接模型"""
__table_args__ = (
Index("ix_sourcelink_file_name", "file_id", "name"),
Index("ix_sourcelink_object_name", "object_id", "name"),
)
name: str = Field(max_length=255, description="链接名称")
downloads: int = Field(default=0, sa_column_kwargs={"server_default": "0"}, description="通过此链接的下载次数")
name: str = Field(max_length=255)
"""链接名称"""
downloads: int = Field(default=0, sa_column_kwargs={"server_default": "0"})
"""通过此链接的下载次数"""
# 外键
file_id: int = Field(foreign_key="file.id", index=True, description="关联的文件ID")
object_id: int = Field(foreign_key="object.id", index=True)
"""关联的对象ID必须是文件类型"""
# 关系
file: "File" = Relationship(back_populates="source_links")
object: "Object" = Relationship(back_populates="source_links")
"""关联的对象"""