feat: barebones following/followers collections

This commit is contained in:
əlemi 2024-03-22 01:52:02 +01:00
parent 5c1ee72d68
commit 20415a0386
Signed by: alemi
GPG key ID: A4895B84D311642C
3 changed files with 32 additions and 0 deletions

View file

@ -22,6 +22,34 @@ pub async fn view(State(ctx) : State<Context>, Path(id): Path<String>) -> Result
} }
} }
pub async fn followers(
State(ctx): State<Context>,
Path(id): Path<String>,
) -> Result<JsonLD<serde_json::Value>, StatusCode> {
Ok(JsonLD(
serde_json::Value::new_object()
.set_id(Some(&format!("{}/users/{}/followers", ctx.base(), id)))
.set_collection_type(Some(CollectionType::OrderedCollection))
.set_total_items(Some(0))
.set_first(Node::link(format!("{}/users/{}/followers?page=true", ctx.base(), id)))
.ld_context()
))
}
pub async fn following(
State(ctx): State<Context>,
Path(id): Path<String>,
) -> Result<JsonLD<serde_json::Value>, StatusCode> {
Ok(JsonLD(
serde_json::Value::new_object()
.set_id(Some(&format!("{}/users/{}/following", ctx.base(), id)))
.set_collection_type(Some(CollectionType::OrderedCollection))
.set_total_items(Some(0))
.set_first(Node::link(format!("{}/users/{}/following?page=true", ctx.base(), id)))
.ld_context()
))
}
pub async fn outbox( pub async fn outbox(
State(ctx): State<Context>, State(ctx): State<Context>,
Path(id): Path<String>, Path(id): Path<String>,

View file

@ -30,6 +30,8 @@ pub async fn nodeinfo_discovery(State(ctx): State<Context>) -> Json<NodeInfoDisc
}) })
} }
// TODO either vendor or fork nodeinfo-rs because it still represents "repository" and "homepage"
// even if None! technically leads to invalid nodeinfo 2.0
pub async fn nodeinfo(State(ctx): State<Context>, Path(version): Path<String>) -> Result<Json<nodeinfo::NodeInfoOwned>, StatusCode> { pub async fn nodeinfo(State(ctx): State<Context>, Path(version): Path<String>) -> Result<Json<nodeinfo::NodeInfoOwned>, StatusCode> {
// TODO it's unsustainable to count these every time, especially comments since it's a complex // TODO it's unsustainable to count these every time, especially comments since it's a complex
// filter! keep these numbers caches somewhere, maybe db, so that we can just look them up // filter! keep these numbers caches somewhere, maybe db, so that we can just look them up

View file

@ -86,6 +86,8 @@ pub async fn serve(db: DatabaseConnection, domain: String) {
.route("/users/:id", get(ap::user::view)) .route("/users/:id", get(ap::user::view))
.route("/users/:id/inbox", post(ap::user::inbox)) .route("/users/:id/inbox", post(ap::user::inbox))
.route("/users/:id/outbox", get(ap::user::outbox)) .route("/users/:id/outbox", get(ap::user::outbox))
.route("/users/:id/followers", get(ap::user::followers))
.route("/users/:id/following", get(ap::user::following))
// specific object routes // specific object routes
.route("/activities/:id", get(ap::activity::view)) .route("/activities/:id", get(ap::activity::view))
.route("/objects/:id", get(ap::object::view)) .route("/objects/:id", get(ap::object::view))