[lint] actor.py

This commit is contained in:
SouthFox 2023-07-29 20:49:01 +08:00
parent 64278302fa
commit 1751a78a59

View file

@ -10,15 +10,13 @@ from app import models
from app.database import AsyncSession
if typing.TYPE_CHECKING:
from app.models import Actor as ActorModel
async def fetch_actor(
db_session : AsyncSession,
actor_id : str,
db_session: AsyncSession,
actor_id: str,
) -> "ActorModel":
"""Fetch actor on db, if not exist will be grabed and stored
in db."""
@ -39,8 +37,8 @@ async def fetch_actor(
async def save_actor(
ap_object : dict,
db_session : AsyncSession
ap_object: dict,
db_session: AsyncSession
) -> "ActorModel":
"""Save actor to db."""
logger.info("save actor " + ap_object["id"])
@ -57,8 +55,8 @@ async def save_actor(
return actor
def _handle (
ap_object :dict
def _handle(
ap_object: dict,
) -> str:
ap_id = urlparse(ap_object["id"])
if not ap_id.hostname:
@ -76,7 +74,8 @@ async def get_public_key(
"""Give key id and reutrn public key."""
existing_actor = (
await db_session.scalars(
select(models.Actor).where(models.Actor.ap_id == key_id.split("#")[0])
select(models.Actor).where(
models.Actor.ap_id == key_id.split("#")[0])
)
).one_or_none()
public_key = existing_actor.ap_object["publicKey"]["publicKeyPem"]