Start support for authoring articles
This commit is contained in:
parent
e363ae2802
commit
24f3f94056
10 changed files with 132 additions and 8 deletions
46
app/main.py
46
app/main.py
|
@ -215,6 +215,7 @@ async def index(
|
|||
models.OutboxObject.visibility == ap.VisibilityEnum.PUBLIC,
|
||||
models.OutboxObject.is_deleted.is_(False),
|
||||
models.OutboxObject.is_hidden_from_homepage.is_(False),
|
||||
models.OutboxObject.ap_type != "Article",
|
||||
)
|
||||
q = select(models.OutboxObject).where(*where)
|
||||
total_count = await db_session.scalar(
|
||||
|
@ -257,6 +258,51 @@ async def index(
|
|||
)
|
||||
|
||||
|
||||
@app.get("/articles")
|
||||
async def articles(
|
||||
request: Request,
|
||||
db_session: AsyncSession = Depends(get_db_session),
|
||||
_: httpsig.HTTPSigInfo = Depends(httpsig.httpsig_checker),
|
||||
page: int | None = None,
|
||||
) -> templates.TemplateResponse | ActivityPubResponse:
|
||||
# TODO: special ActivityPub collection for Article
|
||||
|
||||
where = (
|
||||
models.OutboxObject.visibility == ap.VisibilityEnum.PUBLIC,
|
||||
models.OutboxObject.is_deleted.is_(False),
|
||||
models.OutboxObject.is_hidden_from_homepage.is_(False),
|
||||
models.OutboxObject.ap_type == "Article",
|
||||
)
|
||||
q = select(models.OutboxObject).where(*where)
|
||||
|
||||
outbox_objects_result = await db_session.scalars(
|
||||
q.options(
|
||||
joinedload(models.OutboxObject.outbox_object_attachments).options(
|
||||
joinedload(models.OutboxObjectAttachment.upload)
|
||||
),
|
||||
joinedload(models.OutboxObject.relates_to_inbox_object).options(
|
||||
joinedload(models.InboxObject.actor),
|
||||
),
|
||||
joinedload(models.OutboxObject.relates_to_outbox_object).options(
|
||||
joinedload(models.OutboxObject.outbox_object_attachments).options(
|
||||
joinedload(models.OutboxObjectAttachment.upload)
|
||||
),
|
||||
),
|
||||
).order_by(models.OutboxObject.ap_published_at.desc())
|
||||
)
|
||||
outbox_objects = outbox_objects_result.unique().all()
|
||||
|
||||
return await templates.render_template(
|
||||
db_session,
|
||||
request,
|
||||
"articles.html",
|
||||
{
|
||||
"request": request,
|
||||
"objects": outbox_objects,
|
||||
},
|
||||
)
|
||||
|
||||
|
||||
async def _build_followx_collection(
|
||||
db_session: AsyncSession,
|
||||
model_cls: Type[models.Following | models.Follower],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue