From 923be7e1e91dd867f1827c0ad68f44bea035e609 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Thu, 21 Sep 2023 19:59:29 +0800 Subject: [PATCH] =?UTF-8?q?feat=20=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=94=AF=E6=8C=81=E5=88=A0=E9=99=A4=E6=BA=90?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/endpoints/history.py | 20 +++++++++++--------- app/db/models/__init__.py | 8 ++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/api/endpoints/history.py b/app/api/endpoints/history.py index c71800a4..fff975a0 100644 --- a/app/api/endpoints/history.py +++ b/app/api/endpoints/history.py @@ -62,20 +62,22 @@ def transfer_history(title: str = None, @router.delete("/transfer", summary="删除转移历史记录", response_model=schemas.Response) def delete_transfer_history(history_in: schemas.TransferHistory, - delete_file: bool = False, + deletesrc: bool = False, + deletedest: bool = False, db: Session = Depends(get_db), _: schemas.TokenPayload = Depends(verify_token)) -> Any: """ 删除转移历史记录 """ - # 触发删除事件 - if delete_file: - history = TransferHistory.get(db, history_in.id) - if not history: - return schemas.Response(success=False, msg="记录不存在") - # 册除文件 - if history.dest: - TransferChain(db).delete_files(Path(history.dest)) + history = TransferHistory.get(db, history_in.id) + if not history: + return schemas.Response(success=False, msg="记录不存在") + # 册除媒体库文件 + if deletedest and history.dest: + TransferChain(db).delete_files(Path(history.dest)) + # 删除源文件 + if deletesrc and history.src: + TransferChain(db).delete_files(Path(history.src)) # 删除记录 TransferHistory.delete(db, history_in.id) return schemas.Response(success=True) diff --git a/app/db/models/__init__.py b/app/db/models/__init__.py index fc7b116c..086c7f27 100644 --- a/app/db/models/__init__.py +++ b/app/db/models/__init__.py @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, Self, List from sqlalchemy.orm import as_declarative, declared_attr, Session @@ -16,13 +16,13 @@ class Base: db.rollback() raise err - def create(self, db: Session): + def create(self, db: Session) -> Self: db.add(self) self.commit(db) return self @classmethod - def get(cls, db: Session, rid: int): + def get(cls, db: Session, rid: int) -> Self: return db.query(cls).filter(cls.id == rid).first() def update(self, db: Session, payload: dict): @@ -42,7 +42,7 @@ class Base: Base.commit(db) @classmethod - def list(cls, db: Session): + def list(cls, db: Session) -> List[Self]: return db.query(cls).all() def to_dict(self):