fix exists_local

This commit is contained in:
jxxghp
2025-11-20 12:43:19 +08:00
parent f59d225029
commit 728ea6172a
+17
View File
@@ -65,6 +65,14 @@ class MediaServerItem(Base):
@classmethod @classmethod
@db_query @db_query
def exists_by_title(cls, db: Session, title: str, mtype: str, year: str): def exists_by_title(cls, db: Session, title: str, mtype: str, year: str):
if not mtype and not year:
return db.query(cls).filter(cls.title == title).first()
elif not year:
return db.query(cls).filter(cls.title == title,
cls.item_type == mtype).first()
elif not mtype:
return db.query(cls).filter(cls.title == title,
cls.year == str(year)).first()
return db.query(cls).filter(cls.title == title, return db.query(cls).filter(cls.title == title,
cls.item_type == mtype, cls.item_type == mtype,
cls.year == str(year)).first() cls.year == str(year)).first()
@@ -85,6 +93,15 @@ class MediaServerItem(Base):
@classmethod @classmethod
@async_db_query @async_db_query
async def async_exists_by_title(cls, db: AsyncSession, title: str, mtype: str, year: str): async def async_exists_by_title(cls, db: AsyncSession, title: str, mtype: str, year: str):
if not mtype and not year:
result = await db.execute(select(cls).filter(cls.title == title))
elif not year:
result = await db.execute(select(cls).filter(cls.title == title,
cls.item_type == mtype))
elif not mtype:
result = await db.execute(select(cls).filter(cls.title == title,
cls.year == str(year)))
else:
result = await db.execute(select(cls).filter(cls.title == title, result = await db.execute(select(cls).filter(cls.title == title,
cls.item_type == mtype, cls.item_type == mtype,
cls.year == str(year))) cls.year == str(year)))