增加对上传图片文件名称的校验

This commit is contained in:
2025-02-25 17:21:41 +08:00
parent 7b7548f896
commit baadf6c197
5 changed files with 31 additions and 0 deletions

View File

@ -38,6 +38,7 @@ class ProjectLabel(DbCommon):
class ProjectImage(DbCommon):
"""项目图片表"""
__tablename__ = "project_image"
file_name: Mapped[str] = mapped_column(String(64), nullable=False)
image_url: Mapped[str] = mapped_column(String(255), nullable=False)
thumb_image_url: Mapped[str] = mapped_column(String(255), nullable=False)
project_id: Mapped[int] = mapped_column(Integer)

View File

@ -14,6 +14,21 @@ def get_image_pager(image: ProjectImagePager, session: Session):
return pager
def check_img_name(project_id: int, file_name: str, session: Session):
"""
根据项目id和文件名称进行查重
:param project_id:
:param file_name:
:param session:
:return:
"""
image = session.query(piModel)\
.filter(piModel.project_id == project_id).filter(piModel.file_name == file_name).first()
if image is not None:
return False
return True
def get_img_url(image_id: int, session: Session):
"""
根据id获取图片

View File

@ -1,3 +1,5 @@
import datetime
from pydantic import BaseModel, Field
from typing import Optional, List
@ -5,6 +7,8 @@ from typing import Optional, List
class ProjectImage(BaseModel):
id: Optional[int] = Field(None, description="id")
project_id: Optional[int] = Field(..., description="项目id")
file_name: Optional[str] = Field(None, description="文件名称")
create_time: Optional[datetime.datetime] = Field(None, description="上传时间")
class Config:
orm_mode = True