2024-04-19 03:29:28 +02:00
|
|
|
use axum::extract::{Path, Query, State};
|
2024-04-24 02:31:35 +02:00
|
|
|
use sea_orm::{ColumnTrait, Condition, PaginatorTrait, QueryFilter};
|
2024-04-19 03:29:28 +02:00
|
|
|
|
2024-04-24 02:31:35 +02:00
|
|
|
use crate::{model, routes::activitypub::{JsonLD, Pagination}, server::{auth::AuthIdentity, Context}, url};
|
2024-04-19 03:29:28 +02:00
|
|
|
|
|
|
|
pub async fn get(
|
|
|
|
State(ctx): State<Context>,
|
|
|
|
Path(id): Path<String>,
|
|
|
|
AuthIdentity(auth): AuthIdentity,
|
|
|
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
|
|
|
let context = if id.starts_with('+') {
|
|
|
|
format!("https://{}", id.replacen('+', "", 1).replace('@', "/"))
|
|
|
|
} else {
|
|
|
|
url!(ctx, "/context/{id}")
|
|
|
|
};
|
|
|
|
|
2024-04-24 02:31:35 +02:00
|
|
|
let count = model::addressing::Entity::find_addressed()
|
2024-04-19 03:29:28 +02:00
|
|
|
.filter(auth.filter_condition())
|
|
|
|
.filter(model::object::Column::Context.eq(context))
|
|
|
|
.count(ctx.db())
|
|
|
|
.await?;
|
|
|
|
|
2024-04-24 02:31:35 +02:00
|
|
|
crate::server::builders::collection(&url!(ctx, "/context/{id}"), Some(count))
|
2024-04-19 03:29:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn page(
|
|
|
|
State(ctx): State<Context>,
|
|
|
|
Path(id): Path<String>,
|
|
|
|
Query(page): Query<Pagination>,
|
|
|
|
AuthIdentity(auth): AuthIdentity,
|
|
|
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
|
|
|
let context = if id.starts_with('+') {
|
2024-04-22 01:01:42 +02:00
|
|
|
id.replacen('+', "https://", 1).replace('@', "/")
|
2024-04-22 00:01:09 +02:00
|
|
|
} else if id.starts_with("tag:") {
|
|
|
|
id.clone()
|
2024-04-19 03:29:28 +02:00
|
|
|
} else {
|
2024-04-22 00:01:09 +02:00
|
|
|
url!(ctx, "/context/{id}") // TODO need a better way to figure out which ones are our contexts
|
2024-04-19 03:29:28 +02:00
|
|
|
};
|
|
|
|
|
2024-04-24 02:31:35 +02:00
|
|
|
crate::server::builders::paginate(
|
|
|
|
url!(ctx, "/context/{id}/page"),
|
|
|
|
Condition::all()
|
|
|
|
.add(auth.filter_condition())
|
|
|
|
.add(model::object::Column::Context.eq(context)),
|
|
|
|
ctx.db(),
|
|
|
|
page
|
|
|
|
)
|
|
|
|
.await
|
2024-04-19 03:29:28 +02:00
|
|
|
}
|