feat: introduced arbitrary fetch route for users

This commit is contained in:
əlemi 2024-04-21 19:15:47 +02:00
parent 48bba8af40
commit 624492bcfb
Signed by: alemi
GPG key ID: A4895B84D311642C
2 changed files with 34 additions and 2 deletions

View file

@ -1,7 +1,8 @@
use apb::{ActorMut, BaseMut, ObjectMut, PublicKeyMut};
use axum::{extract::State, http::HeaderMap, response::{IntoResponse, Redirect, Response}};
use axum::{extract::{Query, State}, http::HeaderMap, response::{IntoResponse, Redirect, Response}, Json};
use reqwest::Method;
use crate::{server::Context, url};
use crate::{errors::UpubError, server::{auth::{AuthIdentity, Identity}, fetcher::Fetcher, Context}, url};
use super::{jsonld::LD, JsonLD};
@ -35,3 +36,32 @@ pub async fn view(
.ld_context()
).into_response())
}
#[derive(Debug, serde::Deserialize)]
pub struct FetchPath {
id: String,
}
pub async fn debug(
State(ctx): State<Context>,
Query(query): Query<FetchPath>,
AuthIdentity(auth): AuthIdentity,
) -> crate::Result<Json<serde_json::Value>> {
// only local users can request debug fetches
if !matches!(auth, Identity::Local(_)) {
return Err(UpubError::unauthorized());
}
Ok(Json(
Context::request(
Method::GET,
&query.id,
None,
&ctx.base(),
&ctx.app().private_key,
ctx.domain(),
)
.await?
.json::<serde_json::Value>()
.await?
))
}

View file

@ -24,6 +24,8 @@ impl ActivityPubRouter for Router<crate::server::Context> {
self
// core server inbox/outbox, maybe for feeds? TODO do we need these?
.route("/", get(ap::application::view))
// fetch route, to debug and retreive remote objects
.route("/dbg", get(ap::application::debug))
// TODO shared inboxes and instance stream will come later, just use users *boxes for now
.route("/inbox", post(ap::inbox::post))
.route("/inbox", get(ap::inbox::get))