diff --git a/app/config.py b/app/config.py index a36075a..42de93f 100644 --- a/app/config.py +++ b/app/config.py @@ -30,6 +30,7 @@ class Config(pydantic.BaseModel): hides_following: bool = False inbox_retention_days: int = 15 + post_token: str | None = None def load_config() -> Config: try: @@ -66,3 +67,4 @@ USER_AGENT = "Fediverse Application/" + VERSION AP_CONTENT_TYPE = "application/activity+json" MANUALLY_APPROVES_FOLLOWERS = CONFIG.manually_approves_followers +POST_TOKEN = CONFIG.post_token diff --git a/app/main.py b/app/main.py index 3b8e5b9..b6491dc 100644 --- a/app/main.py +++ b/app/main.py @@ -20,7 +20,7 @@ from app.utils import precheck from app.database import get_db_session from app.config import DEBUG from app.activitypub import ME -from app.config import BASE_URL +from app.config import BASE_URL, POST_TOKEN from app.config import DOMAIN from app.config import ID from app.config import USERNAME @@ -69,6 +69,37 @@ async def inbox( return Response(status_code=406) +@app.post("/outbox") +async def outbox( + request: Request, + db_session: AsyncSession = Depends(get_db_session), +) -> Response: + payload = await request.body() + logger.info(payload) + + if POST_TOKEN is not None \ + and POST_TOKEN == request.headers.get("post_token"): + logger.info("True token") + + from app.activitypub import VisibilityEnum + from app.boxes import _send_create + from app.orgpython import to_html + + content = payload.decode("utf-8") + content = to_html(content).replace("\n", "") + + await _send_create( + db_session, + "Note", + content, + VisibilityEnum.PUBLIC + ) + return Response(status_code=200) + else: + logger.warning("Non-valid post token!") + return Response(status_code=406) + + @app.get("/tail/{public_id}") async def outbox_activity_by_public_id( public_id: str,