[chore] format code
All checks were successful
ci/woodpecker/push/lint Pipeline was successful
ci/woodpecker/push/test Pipeline was successful

This commit is contained in:
SouthFox 2023-08-02 20:53:09 +08:00
parent 3eb22ce9db
commit da6b51fc5f
5 changed files with 20 additions and 11 deletions

View file

@ -227,9 +227,9 @@ async def process_incoming(
async def _handle_follow( async def _handle_follow(
db_session : AsyncSession, db_session: AsyncSession,
actor : Actor, actor: Actor,
inbox_object : InboxObject, inbox_object: InboxObject,
) -> bool: ) -> bool:
if ME["id"] != inbox_object.ap_object["object"]: #type: ignore if ME["id"] != inbox_object.ap_object["object"]: #type: ignore
# await db_session.delete(ap_object) # await db_session.delete(ap_object)
@ -245,9 +245,9 @@ async def _handle_follow(
async def _send_accept( async def _send_accept(
db_session: AsyncSession, db_session: AsyncSession,
actor : Actor, actor: Actor,
inbox_object : InboxObject, inbox_object: InboxObject,
) -> None : ) -> None:
follower = models.Follower( follower = models.Follower(
actor_id=inbox_object.actor_id, actor_id=inbox_object.actor_id,
inbox_object_id=inbox_object.id, inbox_object_id=inbox_object.id,
@ -287,8 +287,8 @@ async def _send_accept(
async def _handle_undo( async def _handle_undo(
db_session : AsyncSession, db_session: AsyncSession,
inbox_object : dict inbox_object: dict
) -> bool: ) -> bool:
if inbox_object["object"]["object"] != ME["id"]: if inbox_object["object"]["object"] != ME["id"]:
logger.warning("Wrong undo object! " logger.warning("Wrong undo object! "

View file

@ -13,6 +13,7 @@ from app.config import DB_PATH
from app.config import DEBUG from app.config import DEBUG
from app.config import SQLALCHEMY_DATABASE_URL from app.config import SQLALCHEMY_DATABASE_URL
engine = create_engine( engine = create_engine(
SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False, "timeout": 15} SQLALCHEMY_DATABASE_URL, connect_args={"check_same_thread": False, "timeout": 15}
) )

View file

@ -3,6 +3,7 @@ from pathlib import Path
from Crypto.PublicKey import RSA from Crypto.PublicKey import RSA
def get_pubkey_as_pem(key_path: Path) -> str: def get_pubkey_as_pem(key_path: Path) -> str:
text = key_path.read_text() text = key_path.read_text()
return RSA.import_key(text).public_key().export_key("PEM").decode("utf-8") return RSA.import_key(text).public_key().export_key("PEM").decode("utf-8")

View file

@ -24,9 +24,11 @@ from sqlalchemy.orm import relationship
from datetime import datetime as dtime from datetime import datetime as dtime
from datetime import timezone from datetime import timezone
def now() -> dtime: def now() -> dtime:
return dtime.now(timezone.utc) return dtime.now(timezone.utc)
class Actor(Base, BaseActor): class Actor(Base, BaseActor):
__tablename__ = "actor" __tablename__ = "actor"
@ -43,6 +45,7 @@ class Actor(Base, BaseActor):
is_blocked = Column(Boolean, nullable=False, default=False, server_default="0") is_blocked = Column(Boolean, nullable=False, default=False, server_default="0")
is_deleted = Column(Boolean, nullable=False, default=False, server_default="0") is_deleted = Column(Boolean, nullable=False, default=False, server_default="0")
class InboxObject(Base, BaseObject): class InboxObject(Base, BaseObject):
__tablename__ = "inbox" __tablename__ = "inbox"
@ -90,6 +93,7 @@ class InboxObject(Base, BaseObject):
uselist=False, uselist=False,
) )
class OutboxObject(Base, BaseObject): class OutboxObject(Base, BaseObject):
__tablename__ = "outbox" __tablename__ = "outbox"
@ -147,6 +151,7 @@ class OutboxObject(Base, BaseObject):
uselist=False, uselist=False,
) )
class IncomingActivity(Base): class IncomingActivity(Base):
__tablename__ = "ingress" __tablename__ = "ingress"
@ -156,6 +161,7 @@ class IncomingActivity(Base):
ap_id = Column(String, nullable=True, index=True) ap_id = Column(String, nullable=True, index=True)
ap_object = Column(JSON, nullable=True) ap_object = Column(JSON, nullable=True)
class OutcomingActivity(Base): class OutcomingActivity(Base):
__tablename__ = "push" __tablename__ = "push"
@ -165,6 +171,7 @@ class OutcomingActivity(Base):
ap_id = Column(String, nullable=True, index=True) ap_id = Column(String, nullable=True, index=True)
ap_object = Column(JSON, nullable=True) ap_object = Column(JSON, nullable=True)
class Follower(Base): class Follower(Base):
__tablename__ = "follower" __tablename__ = "follower"
@ -180,6 +187,7 @@ class Follower(Base):
ap_actor_id = Column(String, nullable=False, unique=True) ap_actor_id = Column(String, nullable=False, unique=True)
class Following(Base): class Following(Base):
__tablename__ = "following" __tablename__ = "following"

View file

@ -13,8 +13,8 @@ from sqlalchemy import select
async def inbox_prechecker( async def inbox_prechecker(
request : fastapi.Request, request: fastapi.Request,
db_session : AsyncSession = fastapi.Depends(get_db_session) db_session: AsyncSession = fastapi.Depends(get_db_session)
) -> bool: ) -> bool:
""" """
Check http request Check http request
@ -47,7 +47,6 @@ async def inbox_prechecker(
) )
).one_or_none() ).one_or_none()
): ):
logger.info(f"Dropping unnecessary delete activity " + logger.info(f"Dropping unnecessary delete activity " +
payload["actor"]) payload["actor"])
raise fastapi.HTTPException(status_code=202) raise fastapi.HTTPException(status_code=202)