2024-04-18 04:48:49 +02:00
|
|
|
use axum::extract::{Path, Query, State};
|
2024-04-12 22:21:23 +02:00
|
|
|
use sea_orm::{ColumnTrait, QueryFilter};
|
2024-04-24 02:31:35 +02:00
|
|
|
use crate::{errors::UpubError, model::{self, addressing::Event, attachment::BatchFillable}, server::{auth::AuthIdentity, fetcher::Fetcher, Context}};
|
2024-03-20 05:44:50 +01:00
|
|
|
|
2024-04-18 04:48:49 +02:00
|
|
|
use super::{jsonld::LD, JsonLD, TryFetch};
|
2024-03-20 05:44:50 +01:00
|
|
|
|
2024-04-12 22:21:23 +02:00
|
|
|
pub async fn view(
|
|
|
|
State(ctx): State<Context>,
|
|
|
|
Path(id): Path<String>,
|
|
|
|
AuthIdentity(auth): AuthIdentity,
|
2024-04-18 04:48:49 +02:00
|
|
|
Query(query): Query<TryFetch>,
|
|
|
|
) -> crate::Result<JsonLD<serde_json::Value>> {
|
2024-04-30 01:48:30 +02:00
|
|
|
let aid = ctx.uri("activities", id);
|
2024-04-19 05:26:51 +02:00
|
|
|
if auth.is_local() && query.fetch && !ctx.is_local(&aid) {
|
2024-04-30 01:49:05 +02:00
|
|
|
let obj = ctx.fetch_activity(&aid).await?;
|
|
|
|
if obj.id != aid {
|
|
|
|
return Err(UpubError::Redirect(obj.id));
|
|
|
|
}
|
2024-04-19 05:26:51 +02:00
|
|
|
}
|
|
|
|
|
2024-04-24 02:31:35 +02:00
|
|
|
let row = model::addressing::Entity::find_addressed()
|
2024-04-18 04:48:49 +02:00
|
|
|
.filter(model::activity::Column::Id.eq(&aid))
|
2024-04-12 22:21:23 +02:00
|
|
|
.filter(auth.filter_condition())
|
2024-04-24 02:31:35 +02:00
|
|
|
.into_model::<Event>()
|
2024-03-21 01:42:29 +01:00
|
|
|
.one(ctx.db())
|
2024-04-18 04:48:49 +02:00
|
|
|
.await?
|
2024-04-24 02:31:35 +02:00
|
|
|
.ok_or_else(UpubError::not_found)?;
|
|
|
|
|
|
|
|
let mut attachments = row.load_attachments_batch(ctx.db()).await?;
|
|
|
|
let attach = attachments.remove(row.id());
|
|
|
|
|
|
|
|
Ok(JsonLD(row.ap(attach).ld_context()))
|
2024-03-20 05:44:50 +01:00
|
|
|
}
|
|
|
|
|