feat/send note via HTTP post
This commit is contained in:
parent
a919d31b97
commit
d56251ceb9
2 changed files with 34 additions and 1 deletions
|
@ -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
|
||||
|
|
33
app/main.py
33
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,
|
||||
|
|
Loading…
Reference in a new issue