[refactor] format code & rename var

This commit is contained in:
SouthFox 2023-08-01 22:25:02 +08:00
parent 600d8d2032
commit 652db0ca20

View file

@ -74,8 +74,8 @@ def is_ap_requested(req: Request) -> bool:
@app.get("/") @app.get("/")
async def index( async def index(
request: Request, request: Request,
db_session: AsyncSession = Depends(get_db_session), db_session: AsyncSession = Depends(get_db_session),
): ):
"""Return index page.""" """Return index page."""
if is_ap_requested(request): if is_ap_requested(request):
@ -83,10 +83,12 @@ async def index(
statues = ( statues = (
await db_session.scalars( await db_session.scalars(
select(models.OutboxObject).where( select(models.OutboxObject)
.where(
models.OutboxObject.ap_type == "Note", models.OutboxObject.ap_type == "Note",
models.OutboxObject.is_deleted.is_(False), models.OutboxObject.is_deleted.is_(False),
).order_by(models.OutboxObject.created_at.desc()) )
.order_by(models.OutboxObject.created_at.desc())
) )
).all() ).all()
@ -95,30 +97,24 @@ async def index(
{ {
"request": request, "request": request,
"statues": statues, "statues": statues,
} },
) )
@app.post("/inbox") @app.post("/inbox")
async def inbox( async def inbox(
request: Request, request: Request,
db_session: AsyncSession = Depends(get_db_session), db_session: AsyncSession = Depends(get_db_session),
httpsig_checker=Depends(precheck.inbox_prechecker), httpsig_checker=Depends(precheck.inbox_prechecker),
) -> Response: ) -> Response:
"""ActivityPub inbox endpoint.""" """ActivityPub inbox endpoint."""
payload = await request.json() payload = await request.json()
if not httpsig_checker: if not httpsig_checker:
return Response( return Response(status_code=406, content="invalid http-sig")
status_code=406,
content="invalid http-sig"
)
if not await save_incoming(db_session, payload): if not await save_incoming(db_session, payload):
return Response( return Response(status_code=406, content="invalid activitypub object")
status_code=406,
content="invalid activitypub object"
)
return Response(status_code=202) return Response(status_code=202)
@ -185,7 +181,7 @@ async def wellknown_webfinger(resource: str) -> JSONResponse:
logger.info(f"Got invalid req for {resource}") logger.info(f"Got invalid req for {resource}")
raise HTTPException(status_code=404) raise HTTPException(status_code=404)
out = { response = {
"subject": f"acct:{USERNAME}@{DOMAIN}", "subject": f"acct:{USERNAME}@{DOMAIN}",
"aliases": [ID], "aliases": [ID],
"links": [ "links": [
@ -203,7 +199,7 @@ async def wellknown_webfinger(resource: str) -> JSONResponse:
} }
return JSONResponse( return JSONResponse(
out, response,
media_type="application/jrd+json; charset=utf-8", media_type="application/jrd+json; charset=utf-8",
headers={"Access-Control-Allow-Origin": "*"}, headers={"Access-Control-Allow-Origin": "*"},
) )