add 失败历史记录

This commit is contained in:
jxxghp
2023-06-26 12:30:06 +08:00
parent 178ac334a0
commit 66f081de98
3 changed files with 45 additions and 7 deletions

View File

@ -36,7 +36,7 @@ class TransferHistory(Base):
# 海报
image = Column(String)
# 下载器hash
download_hash = Column(String)
download_hash = Column(String, index=True)
# 转移成功状态
status = Column(Boolean(), default=True)
# 转移失败信息
@ -52,3 +52,7 @@ class TransferHistory(Base):
@staticmethod
def list_by_page(db: Session, page: int = 1, count: int = 30):
return db.query(TransferHistory).offset((page - 1) * count).limit(count).all()
@staticmethod
def get_by_hash(db: Session, download_hash: str):
return db.query(TransferHistory).filter(TransferHistory.download_hash == download_hash).first()

View File

@ -20,5 +20,8 @@ class TransferHistoryOper(DbOper):
"""
新增转移历史
"""
transferhistory = TransferHistory(**kwargs)
return transferhistory.create(self._db)
if kwargs.get("download_hash"):
transferhistory = TransferHistory.get_by_hash(self._db, kwargs.get("download_hash"))
if transferhistory:
transferhistory.delete(self._db, transferhistory.id)
return TransferHistory(**kwargs).create(self._db)