From da6b51fc5f24631ab747333edb11c1935e06993d Mon Sep 17 00:00:00 2001 From: SouthFox Date: Wed, 2 Aug 2023 20:53:09 +0800 Subject: [PATCH] [chore] format code --- app/boxes.py | 16 ++++++++-------- app/database.py | 1 + app/key.py | 1 + app/models.py | 8 ++++++++ app/utils/precheck.py | 5 ++--- 5 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/boxes.py b/app/boxes.py index a5aa1b0..aff5a6f 100644 --- a/app/boxes.py +++ b/app/boxes.py @@ -227,9 +227,9 @@ async def process_incoming( async def _handle_follow( - db_session : AsyncSession, - actor : Actor, - inbox_object : InboxObject, + db_session: AsyncSession, + actor: Actor, + inbox_object: InboxObject, ) -> bool: if ME["id"] != inbox_object.ap_object["object"]: #type: ignore # await db_session.delete(ap_object) @@ -245,9 +245,9 @@ async def _handle_follow( async def _send_accept( db_session: AsyncSession, - actor : Actor, - inbox_object : InboxObject, -) -> None : + actor: Actor, + inbox_object: InboxObject, +) -> None: follower = models.Follower( actor_id=inbox_object.actor_id, inbox_object_id=inbox_object.id, @@ -287,8 +287,8 @@ async def _send_accept( async def _handle_undo( - db_session : AsyncSession, - inbox_object : dict + db_session: AsyncSession, + inbox_object: dict ) -> bool: if inbox_object["object"]["object"] != ME["id"]: logger.warning("Wrong undo object! " diff --git a/app/database.py b/app/database.py index d7e0e3d..5a0ffd5 100644 --- a/app/database.py +++ b/app/database.py @@ -13,6 +13,7 @@ from app.config import DB_PATH from app.config import DEBUG from app.config import SQLALCHEMY_DATABASE_URL + engine = create_engine( SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False, "timeout": 15} ) diff --git a/app/key.py b/app/key.py index 8c98154..c62f1f6 100644 --- a/app/key.py +++ b/app/key.py @@ -3,6 +3,7 @@ from pathlib import Path from Crypto.PublicKey import RSA + def get_pubkey_as_pem(key_path: Path) -> str: text = key_path.read_text() return RSA.import_key(text).public_key().export_key("PEM").decode("utf-8") diff --git a/app/models.py b/app/models.py index 553295b..295c78d 100644 --- a/app/models.py +++ b/app/models.py @@ -24,9 +24,11 @@ from sqlalchemy.orm import relationship from datetime import datetime as dtime from datetime import timezone + def now() -> dtime: return dtime.now(timezone.utc) + class Actor(Base, BaseActor): __tablename__ = "actor" @@ -43,6 +45,7 @@ class Actor(Base, BaseActor): is_blocked = Column(Boolean, nullable=False, default=False, server_default="0") is_deleted = Column(Boolean, nullable=False, default=False, server_default="0") + class InboxObject(Base, BaseObject): __tablename__ = "inbox" @@ -90,6 +93,7 @@ class InboxObject(Base, BaseObject): uselist=False, ) + class OutboxObject(Base, BaseObject): __tablename__ = "outbox" @@ -147,6 +151,7 @@ class OutboxObject(Base, BaseObject): uselist=False, ) + class IncomingActivity(Base): __tablename__ = "ingress" @@ -156,6 +161,7 @@ class IncomingActivity(Base): ap_id = Column(String, nullable=True, index=True) ap_object = Column(JSON, nullable=True) + class OutcomingActivity(Base): __tablename__ = "push" @@ -165,6 +171,7 @@ class OutcomingActivity(Base): ap_id = Column(String, nullable=True, index=True) ap_object = Column(JSON, nullable=True) + class Follower(Base): __tablename__ = "follower" @@ -180,6 +187,7 @@ class Follower(Base): ap_actor_id = Column(String, nullable=False, unique=True) + class Following(Base): __tablename__ = "following" diff --git a/app/utils/precheck.py b/app/utils/precheck.py index b1124e1..8076141 100644 --- a/app/utils/precheck.py +++ b/app/utils/precheck.py @@ -13,8 +13,8 @@ from sqlalchemy import select async def inbox_prechecker( - request : fastapi.Request, - db_session : AsyncSession = fastapi.Depends(get_db_session) + request: fastapi.Request, + db_session: AsyncSession = fastapi.Depends(get_db_session) ) -> bool: """ Check http request @@ -47,7 +47,6 @@ async def inbox_prechecker( ) ).one_or_none() ): - logger.info(f"Dropping unnecessary delete activity " + payload["actor"]) raise fastapi.HTTPException(status_code=202)