forked from alemi/upub
chore: refactored a little
This commit is contained in:
parent
576e809b69
commit
95ab7a50ef
2 changed files with 27 additions and 37 deletions
|
@ -17,7 +17,7 @@ pub async fn page(
|
||||||
State(ctx): State<Context>,
|
State(ctx): State<Context>,
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
Query(page): Query<Pagination>,
|
Query(page): Query<Pagination>,
|
||||||
) -> Result<JsonLD<serde_json::Value>, UpubError> {
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||||
let limit = page.batch.unwrap_or(20).min(50);
|
let limit = page.batch.unwrap_or(20).min(50);
|
||||||
let offset = page.offset.unwrap_or(0);
|
let offset = page.offset.unwrap_or(0);
|
||||||
let activities = model::addressing::Entity::find_activities()
|
let activities = model::addressing::Entity::find_activities()
|
||||||
|
|
|
@ -25,23 +25,23 @@ pub async fn page(
|
||||||
AuthIdentity(auth): AuthIdentity,
|
AuthIdentity(auth): AuthIdentity,
|
||||||
Query(page): Query<Pagination>,
|
Query(page): Query<Pagination>,
|
||||||
) -> crate::Result<JsonLD<serde_json::Value>> {
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
||||||
let uid = ctx.uid(id.clone());
|
let Identity::Local(uid) = auth else {
|
||||||
match auth {
|
// local inbox is only for local users
|
||||||
Identity::Anonymous => Err(StatusCode::FORBIDDEN.into()),
|
return Err(UpubError::forbidden());
|
||||||
Identity::Remote(_) => Err(StatusCode::FORBIDDEN.into()),
|
};
|
||||||
Identity::Local(user) => if uid == user {
|
if uid != ctx.uid(id.clone()) {
|
||||||
|
return Err(UpubError::forbidden());
|
||||||
|
}
|
||||||
let limit = page.batch.unwrap_or(20).min(50);
|
let limit = page.batch.unwrap_or(20).min(50);
|
||||||
let offset = page.offset.unwrap_or(0);
|
let offset = page.offset.unwrap_or(0);
|
||||||
match model::addressing::Entity::find_activities()
|
let activities = model::addressing::Entity::find_activities()
|
||||||
.filter(Condition::all().add(model::addressing::Column::Actor.eq(&user)))
|
.filter(Condition::all().add(model::addressing::Column::Actor.eq(&uid)))
|
||||||
.order_by(model::addressing::Column::Published, Order::Asc)
|
.order_by(model::addressing::Column::Published, Order::Asc)
|
||||||
.offset(offset)
|
.offset(offset)
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
.into_model::<EmbeddedActivity>()
|
.into_model::<EmbeddedActivity>()
|
||||||
.all(ctx.db())
|
.all(ctx.db())
|
||||||
.await
|
.await?;
|
||||||
{
|
|
||||||
Ok(activities) => {
|
|
||||||
Ok(JsonLD(
|
Ok(JsonLD(
|
||||||
ctx.ap_collection_page(
|
ctx.ap_collection_page(
|
||||||
&url!(ctx, "/users/{id}/inbox/page"),
|
&url!(ctx, "/users/{id}/inbox/page"),
|
||||||
|
@ -52,16 +52,6 @@ pub async fn page(
|
||||||
.collect()
|
.collect()
|
||||||
).ld_context()
|
).ld_context()
|
||||||
))
|
))
|
||||||
},
|
|
||||||
Err(e) => {
|
|
||||||
tracing::error!("failed paginating user inbox for {id}: {e}");
|
|
||||||
Err(StatusCode::INTERNAL_SERVER_ERROR.into())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Err(StatusCode::FORBIDDEN.into())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn post(
|
pub async fn post(
|
||||||
|
|
Loading…
Reference in a new issue